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

SVN Revision: 2251
This commit is contained in:
Badlop 2009-06-16 17:47:56 +00:00
parent 7f8c01b150
commit 65bc1122b2
1 changed files with 74 additions and 52 deletions

View File

@ -4,7 +4,7 @@
%%% Purpose : Implements XMPP over BOSH (XEP-0205) (formerly known as
%%% HTTP Binding)
%%% 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).
@ -94,8 +94,15 @@
%%%----------------------------------------------------------------------
%%% API
%%%----------------------------------------------------------------------
start(Sid, Key, IP) ->
supervisor:start_child(ejabberd_http_bind_sup, [Sid, Key, IP]).
%% TODO: If compile with no supervisor option, start the session without
%% 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) ->
gen_fsm:start_link(?MODULE, [Sid, Key, IP], ?FSMOPTS).
@ -134,7 +141,37 @@ process_request(Data, IP) ->
XmppDomain ->
%% create new session
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]),
Wait = case
string:to_integer(xml:get_attr_s("wait",Attrs))
@ -150,8 +187,7 @@ process_request(Data, IP) ->
end
end,
Hold = case
string:to_integer(
xml:get_attr_s("hold",Attrs))
string:to_integer(xml:get_attr_s("hold",Attrs))
of
{error, _} ->
(?MAX_REQUESTS - 1);
@ -182,28 +218,7 @@ process_request(Data, IP) ->
version = Version
})
end),
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.
handle_http_put(Sid, Rid, Attrs, Payload, true, IP).
%%%----------------------------------------------------------------------
%%% Callback functions from gen_fsm
@ -1108,3 +1123,10 @@ check_default_xmlns({xmlelement, Name, Attrs, Els} = El) ->
true ->
El
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.