-export([start/0, start_link/0]).
-export([route/3, route_iq/4, route_iq/5, process_iq/3,
- process_iq_reply/3, register_iq_handler/4, get_features/1,
+ process_iq_reply/3, get_features/1,
register_iq_handler/5, register_iq_response_handler/4,
register_iq_response_handler/5, unregister_iq_handler/2,
unregister_iq_response_handler/2, bounce_resource_packet/3]).
XMLNS = xmpp:get_ns(El),
Host = To#jid.lserver,
case ets:lookup(?IQTABLE, {Host, XMLNS}) of
- [{_, Module, Function}] ->
- gen_iq_handler:handle(Host, Module, Function, no_queue,
- From, To, Packet);
[{_, Module, Function, Opts}] ->
gen_iq_handler:handle(Host, Module, Function, Opts,
From, To, Packet);
function = Function,
timer = TRef}).
--spec register_iq_handler(binary(), binary(), module(), function()) -> any().
-register_iq_handler(Host, XMLNS, Module, Fun) ->
- ejabberd_local !
- {register_iq_handler, Host, XMLNS, Module, Fun}.
-
-spec register_iq_handler(binary(), binary(), module(), function(),
- gen_iq_handler:opts()) -> any().
+ gen_iq_handler:opts()) -> ok.
register_iq_handler(Host, XMLNS, Module, Fun, Opts) ->
ejabberd_local !
- {register_iq_handler, Host, XMLNS, Module, Fun, Opts}.
+ {register_iq_handler, Host, XMLNS, Module, Fun, Opts},
+ ok.
-spec unregister_iq_response_handler(binary(), binary()) -> ok.
unregister_iq_response_handler(_Host, ID) ->
catch get_iq_callback(ID), ok.
--spec unregister_iq_handler(binary(), binary()) -> any().
+-spec unregister_iq_handler(binary(), binary()) -> ok.
unregister_iq_handler(Host, XMLNS) ->
- ejabberd_local ! {unregister_iq_handler, Host, XMLNS}.
+ ejabberd_local ! {unregister_iq_handler, Host, XMLNS},
+ ok.
-spec bounce_resource_packet(jid(), jid(), stanza()) -> stop.
bounce_resource_packet(_From, #jid{lresource = <<"">>}, #presence{}) ->
_ -> ok
end,
{noreply, State};
-handle_info({register_iq_handler, Host, XMLNS, Module,
- Function},
- State) ->
- ets:insert(?IQTABLE, {{Host, XMLNS}, Module, Function}),
- {noreply, State};
handle_info({register_iq_handler, Host, XMLNS, Module,
Function, Opts},
State) ->
get_vh_session_list/1,
get_vh_session_number/1,
get_vh_by_backend/1,
- register_iq_handler/4,
register_iq_handler/5,
unregister_iq_handler/2,
force_update_presence/1,
Mod = get_sm_backend(LServer),
length(online(Mod:get_sessions(LServer))).
-register_iq_handler(Host, XMLNS, Module, Fun) ->
- ejabberd_sm ! {register_iq_handler, Host, XMLNS, Module, Fun}.
-
--spec register_iq_handler(binary(), binary(), atom(), atom(), list()) -> any().
+-spec register_iq_handler(binary(), binary(), atom(), atom(), list()) -> ok.
register_iq_handler(Host, XMLNS, Module, Fun, Opts) ->
- ejabberd_sm ! {register_iq_handler, Host, XMLNS, Module, Fun, Opts}.
+ ejabberd_sm ! {register_iq_handler, Host, XMLNS, Module, Fun, Opts},
+ ok.
--spec unregister_iq_handler(binary(), binary()) -> any().
+-spec unregister_iq_handler(binary(), binary()) -> ok.
unregister_iq_handler(Host, XMLNS) ->
- ejabberd_sm ! {unregister_iq_handler, Host, XMLNS}.
+ ejabberd_sm ! {unregister_iq_handler, Host, XMLNS},
+ ok.
%% Why the hell do we have so many similar kicks?
c2s_handle_info(#{lang := Lang} = State, replaced) ->
ok
end,
{noreply, State};
-handle_info({register_iq_handler, Host, XMLNS, Module, Function}, State) ->
- ets:insert(sm_iqtable, {{Host, XMLNS}, Module, Function}),
- {noreply, State};
handle_info({register_iq_handler, Host, XMLNS, Module,
Function, Opts},
State) ->
XMLNS = xmpp:get_ns(El),
Host = To#jid.lserver,
case ets:lookup(sm_iqtable, {Host, XMLNS}) of
- [{_, Module, Function}] ->
- gen_iq_handler:handle(Host, Module, Function, no_queue,
- From, To, Packet);
[{_, Module, Function, Opts}] ->
gen_iq_handler:handle(Host, Module, Function, Opts,
From, To, Packet);
gen_server:start_link(?MODULE, [Host, Module, Function],
[]).
--spec add_iq_handler(module(), binary(), binary(), module(), atom(), type()) -> any().
+-spec add_iq_handler(module(), binary(), binary(), module(), atom(), type()) -> ok.
add_iq_handler(Component, Host, NS, Module, Function,
Type) ->
Function, parallel)
end.
--spec remove_iq_handler(component(), binary(), binary()) -> any().
+-spec remove_iq_handler(component(), binary(), binary()) -> ok.
remove_iq_handler(Component, Host, NS) ->
Component:unregister_iq_handler(Host, NS).
-type opts() :: [{atom(), any()}].
-type db_type() :: sql | mnesia | riak.
--callback start(binary(), opts()) -> any().
+-callback start(binary(), opts()) -> ok | {ok, pid()}.
-callback stop(binary()) -> any().
-callback mod_opt_type(atom()) -> fun((term()) -> term()) | [atom()].
-callback depends(binary(), opts()) -> [{module(), hard | soft}].
{error, not_found_in_config}
end.
--spec start_module(binary(), atom(), opts()) -> any().
+-spec start_module(binary(), atom(), opts()) -> ok | {ok, pid()}.
start_module(Host, Module, Opts0) ->
+ ?DEBUG("loading ~s at ~s", [Module, Host]),
Opts = validate_opts(Module, Opts0),
ets:insert(ejabberd_modules,
#ejabberd_module{module_host = {Module, Host},
opts = Opts}),
- try Module:start(Host, Opts) catch
- Class:Reason ->
+ try case Module:start(Host, Opts) of
+ ok -> ok;
+ {ok, Pid} when is_pid(Pid) -> {ok, Pid};
+ Err -> erlang:error(Err)
+ end
+ catch Class:Reason ->
ets:delete(ejabberd_modules, {Module, Host}),
ErrorText =
- io_lib:format("Problem starting the module ~p for host "
- "~p ~n options: ~p~n ~p: ~p~n~p",
+ io_lib:format("Problem starting the module ~s for host "
+ "~s ~n options: ~p~n ~p: ~p~n~p",
[Module, Host, Opts, Class, Reason,
erlang:get_stacktrace()]),
?CRITICAL_MSG(ErrorText, []),
ejabberd_hooks:add(adhoc_local_commands, Host, ?MODULE, announce_commands, 50),
ejabberd_hooks:add(c2s_self_presence, Host,
?MODULE, send_motd, 50),
- register(gen_mod:get_module_proc(Host, ?PROCNAME),
- proc_lib:spawn(?MODULE, init, [])).
+ Pid = proc_lib:spawn(?MODULE, init, []),
+ register(gen_mod:get_module_proc(Host, ?PROCNAME), Pid),
+ {ok, Pid}.
depends(_Host, _Opts) ->
[{mod_adhoc, hard}].
start(Host, Opts) ->
start_jiffy(Opts),
+ Mod = gen_mod:ram_db_mod(global, ?MODULE),
+ Mod:init(),
TmpSup = gen_mod:get_module_proc(Host, ?PROCNAME),
TmpSupSpec = {TmpSup,
{ejabberd_tmp_sup, start_link, [TmpSup, ejabberd_bosh]},
permanent, infinity, supervisor, [ejabberd_tmp_sup]},
- supervisor:start_child(ejabberd_sup, TmpSupSpec),
- Mod = gen_mod:ram_db_mod(global, ?MODULE),
- Mod:init().
+ supervisor:start_child(ejabberd_sup, TmpSupSpec).
stop(Host) ->
TmpSup = gen_mod:get_module_proc(Host, ?PROCNAME),
start(Host, Opts) ->
case mod_proxy65_service:add_listener(Host, Opts) of
- {error, _} = Err -> erlang:error(Err);
- _ ->
- Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
- ChildSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
- transient, infinity, supervisor, [?MODULE]},
- case supervisor:start_child(ejabberd_sup, ChildSpec) of
- {error, _} = Err -> erlang:error(Err);
- _ ->
- Mod = gen_mod:ram_db_mod(global, ?MODULE),
- Mod:init()
- end
+ {error, _} = Err ->
+ Err;
+ _ ->
+ Mod = gen_mod:ram_db_mod(global, ?MODULE),
+ Mod:init(),
+ Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
+ ChildSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
+ transient, infinity, supervisor, [?MODULE]},
+ supervisor:start_child(ejabberd_sup, ChildSpec)
end.
stop(Host) ->
true ->
ok
end,
- register(gen_mod:get_module_proc(Host, ?PROCNAME),
- spawn(?MODULE, init, [MyHost, Host, Search])).
+ Pid = spawn(?MODULE, init, [MyHost, Host, Search]),
+ register(gen_mod:get_module_proc(Host, ?PROCNAME), Pid),
+ {ok, Pid}.
init(Host, ServerHost, Search) ->
case Search of