From 808029b8686d3b9339aaa1d2539e66960cca4dfd Mon Sep 17 00:00:00 2001 From: Badlop Date: Wed, 17 Nov 2010 20:14:59 +0100 Subject: [PATCH] Fix http-bind supervisor to support multiple vhosts (EJAB-1321) --- src/web/ejabberd_http_bind.erl | 5 ++++- src/web/mod_http_bind.erl | 40 ++++++++++------------------------ 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/web/ejabberd_http_bind.erl b/src/web/ejabberd_http_bind.erl index a51c55356..4d15caadc 100644 --- a/src/web/ejabberd_http_bind.erl +++ b/src/web/ejabberd_http_bind.erl @@ -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"} diff --git a/src/web/mod_http_bind.erl b/src/web/mod_http_bind.erl index 8e750acfd..49433f681 100644 --- a/src/web/mod_http_bind.erl +++ b/src/web/mod_http_bind.erl @@ -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(),