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

Properly warn user and admin when mod_http_bind is not started.(thanks to Michael Remond)

SVN Revision: 2314
This commit is contained in:
Badlop 2009-06-16 18:27:18 +00:00
parent 2c33e72eea
commit 5854edafdd

View File

@ -4,7 +4,7 @@
%%% Purpose : Implements XMPP over BOSH (XEP-0205) (formerly known as %%% Purpose : Implements XMPP over BOSH (XEP-0205) (formerly known as
%%% HTTP Binding) %%% HTTP Binding)
%%% Created : 21 Sep 2005 by Stefan Strigler <steve@zeank.in-berlin.de> %%% Created : 21 Sep 2005 by Stefan Strigler <steve@zeank.in-berlin.de>
%%% Id : $Id: ejabberd_http_bind.erl 944 2009-04-30 18:03:23Z gcant $ %%% Id : $Id: ejabberd_http_bind.erl 949 2009-05-04 01:16:36Z mremond $
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
-module(ejabberd_http_bind). -module(ejabberd_http_bind).
@ -94,8 +94,15 @@
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
%%% API %%% API
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
start(Sid, Key, IP) -> %% TODO: If compile with no supervisor option, start the session without
supervisor:start_child(ejabberd_http_bind_sup, [Sid, Key, IP]). %% supervisor
start(XMPPDomain, Sid, Key, IP) ->
?DEBUG("Starting session", []),
case catch supervisor:start_child(ejabberd_http_bind_sup, [Sid, Key, IP]) of
{ok, Pid} -> {ok, Pid};
_ -> check_bind_module(XMPPDomain),
{error, "Cannot start HTTP bind session"}
end.
start_link(Sid, Key, IP) -> start_link(Sid, Key, IP) ->
gen_fsm:start_link(?MODULE, [Sid, Key, IP], ?FSMOPTS). gen_fsm:start_link(?MODULE, [Sid, Key, IP], ?FSMOPTS).
@ -134,7 +141,37 @@ process_request(Data, IP) ->
XmppDomain -> XmppDomain ->
%% create new session %% create new session
Sid = sha:sha(term_to_binary({now(), make_ref()})), Sid = sha:sha(term_to_binary({now(), make_ref()})),
{ok, Pid} = start(Sid, "", IP), case start(XmppDomain, Sid, "", IP) of
{error, _} ->
{200, ?HEADER, "<body type='terminate' "
"condition='internal-server-error' "
"xmlns='" ++ ?NS_HTTP_BIND ++ "'>BOSH module not started</body"};
{ok, Pid} ->
handle_session_start(Pid, XmppDomain, Sid, Rid, Attrs, Payload, IP)
end
end;
{ok, {Sid, Rid, Attrs, Payload1}} ->
%% old session
StreamStart =
case xml:get_attr_s("xmpp:restart",Attrs) of
"true" ->
true;
_ ->
false
end,
Payload2 = case xml:get_attr_s("type",Attrs) of
"terminate" ->
%% close stream
Payload1 ++ "</stream:stream>";
_ ->
Payload1
end,
handle_http_put(Sid, Rid, Attrs, Payload2, StreamStart, IP);
_ ->
{400, ?HEADER, ""}
end.
handle_session_start(Pid, XmppDomain, Sid, Rid, Attrs, Payload, IP) ->
?DEBUG("got pid: ~p", [Pid]), ?DEBUG("got pid: ~p", [Pid]),
Wait = case Wait = case
string:to_integer(xml:get_attr_s("wait",Attrs)) string:to_integer(xml:get_attr_s("wait",Attrs))
@ -150,8 +187,7 @@ process_request(Data, IP) ->
end end
end, end,
Hold = case Hold = case
string:to_integer( string:to_integer(xml:get_attr_s("hold",Attrs))
xml:get_attr_s("hold",Attrs))
of of
{error, _} -> {error, _} ->
(?MAX_REQUESTS - 1); (?MAX_REQUESTS - 1);
@ -182,28 +218,7 @@ process_request(Data, IP) ->
version = Version version = Version
}) })
end), end),
handle_http_put(Sid, Rid, Attrs, Payload, true, IP) handle_http_put(Sid, Rid, Attrs, Payload, true, IP).
end;
{ok, {Sid, Rid, Attrs, Payload1}} ->
%% old session
StreamStart =
case xml:get_attr_s("xmpp:restart",Attrs) of
"true" ->
true;
_ ->
false
end,
Payload2 = case xml:get_attr_s("type",Attrs) of
"terminate" ->
%% close stream
Payload1 ++ "</stream:stream>";
_ ->
Payload1
end,
handle_http_put(Sid, Rid, Attrs, Payload2, StreamStart, IP);
_ ->
{400, ?HEADER, ""}
end.
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
%%% Callback functions from gen_fsm %%% Callback functions from gen_fsm
@ -1108,3 +1123,10 @@ check_default_xmlns({xmlelement, Name, Attrs, Els} = El) ->
true -> true ->
El El
end. end.
check_bind_module(XmppDomain) ->
case gen_mod:is_loaded(XmppDomain, mod_http_bind) of
true -> ok;
false -> ?ERROR_MSG("You are trying to use HTTP Bind (BOSH), but the module mod_http_bind is not started.~n"
"Check your 'modules' section in your ejabberd configuration file.",[])
end.