25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

Fix http-bind supervisor to support multiple vhosts (EJAB-1321)

This commit is contained in:
Badlop 2010-11-17 20:14:59 +01:00
parent cfd377b98e
commit 808029b868
2 changed files with 16 additions and 29 deletions

View File

@ -112,6 +112,8 @@
-define(PROCESS_DELAY_MIN, 0).
-define(PROCESS_DELAY_MAX, 1000).
%% Line copied from mod_http_bind.erl
-define(PROCNAME_MHB, ejabberd_mod_http_bind).
%%%----------------------------------------------------------------------
%%% API
@ -120,7 +122,8 @@
%% supervisor
start(XMPPDomain, Sid, Key, IP) ->
?DEBUG("Starting session", []),
case catch supervisor:start_child(ejabberd_http_bind_sup, [Sid, Key, IP]) of
SupervisorProc = gen_mod:get_module_proc(XMPPDomain, ?PROCNAME_MHB),
case catch supervisor:start_child(SupervisorProc, [Sid, Key, IP]) of
{ok, Pid} -> {ok, Pid};
_ -> check_bind_module(XMPPDomain),
{error, "Cannot start HTTP bind session"}

View File

@ -48,6 +48,8 @@
-include("ejabberd_http.hrl").
-include("http_bind.hrl").
-define(PROCNAME_MHB, ejabberd_mod_http_bind).
%% Duplicated from ejabberd_http_bind.
%% TODO: move to hrl file.
-record(http_bind, {id, pid, to, hold, wait, process_delay, version}).
@ -98,41 +100,23 @@ get_human_html_xmlel() ->
%%%----------------------------------------------------------------------
%%% BEHAVIOUR CALLBACKS
%%%----------------------------------------------------------------------
start(_Host, _Opts) ->
start(Host, _Opts) ->
setup_database(),
HTTPBindSupervisor =
{ejabberd_http_bind_sup,
Proc = gen_mod:get_module_proc(Host, ?PROCNAME_MHB),
ChildSpec =
{Proc,
{ejabberd_tmp_sup, start_link,
[ejabberd_http_bind_sup, ejabberd_http_bind]},
[Proc, ejabberd_http_bind]},
permanent,
infinity,
supervisor,
[ejabberd_tmp_sup]},
case supervisor:start_child(ejabberd_sup, HTTPBindSupervisor) of
{ok, _Pid} ->
ok;
{ok, _Pid, _Info} ->
ok;
{error, {already_started, _PidOther}} ->
% mod_http_bind is already started so it will not be started again
ok;
{error, Error} ->
exit({start_child_error, Error})
end.
supervisor:start_child(ejabberd_sup, ChildSpec).
stop(_Host) ->
case supervisor:terminate_child(ejabberd_sup, ejabberd_http_bind_sup) of
ok ->
ok;
{error, Error} ->
exit({terminate_child_error, Error})
end,
case supervisor:delete_child(ejabberd_sup, ejabberd_http_bind_sup) of
ok ->
ok;
{error, Error2} ->
exit({delete_child_error, Error2})
end.
stop(Host) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME_MHB),
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc).
setup_database() ->
migrate_database(),