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

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

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,55 +141,14 @@ 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
?DEBUG("got pid: ~p", [Pid]), {error, _} ->
Wait = case {200, ?HEADER, "<body type='terminate' "
string:to_integer(xml:get_attr_s("wait",Attrs)) "condition='internal-server-error' "
of "xmlns='" ++ ?NS_HTTP_BIND ++ "'>BOSH module not started</body"};
{error, _} -> {ok, Pid} ->
?MAX_WAIT; handle_session_start(Pid, XmppDomain, Sid, Rid, Attrs, Payload, IP)
{CWait, _} -> end
if
(CWait > ?MAX_WAIT) ->
?MAX_WAIT;
true ->
CWait
end
end,
Hold = case
string:to_integer(
xml:get_attr_s("hold",Attrs))
of
{error, _} ->
(?MAX_REQUESTS - 1);
{CHold, _} ->
if
(CHold > (?MAX_REQUESTS - 1)) ->
(?MAX_REQUESTS - 1);
true ->
CHold
end
end,
Version =
case catch list_to_float(
xml:get_attr_s("ver", Attrs)) of
{'EXIT', _} -> 0.0;
V -> V
end,
XmppVersion = xml:get_attr_s("xmpp:version", Attrs),
mnesia:transaction(
fun() ->
mnesia:write(
#http_bind{id = Sid,
pid = Pid,
to = {XmppDomain,
XmppVersion},
hold = Hold,
wait = Wait,
version = Version
})
end),
handle_http_put(Sid, Rid, Attrs, Payload, true, IP)
end; end;
{ok, {Sid, Rid, Attrs, Payload1}} -> {ok, {Sid, Rid, Attrs, Payload1}} ->
%% old session %% old session
@ -205,6 +171,55 @@ process_request(Data, IP) ->
{400, ?HEADER, ""} {400, ?HEADER, ""}
end. 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))
of
{error, _} ->
?MAX_WAIT;
{CWait, _} ->
if
(CWait > ?MAX_WAIT) ->
?MAX_WAIT;
true ->
CWait
end
end,
Hold = case
string:to_integer(xml:get_attr_s("hold",Attrs))
of
{error, _} ->
(?MAX_REQUESTS - 1);
{CHold, _} ->
if
(CHold > (?MAX_REQUESTS - 1)) ->
(?MAX_REQUESTS - 1);
true ->
CHold
end
end,
Version =
case catch list_to_float(
xml:get_attr_s("ver", Attrs)) of
{'EXIT', _} -> 0.0;
V -> V
end,
XmppVersion = xml:get_attr_s("xmpp:version", Attrs),
mnesia:transaction(
fun() ->
mnesia:write(
#http_bind{id = Sid,
pid = Pid,
to = {XmppDomain,
XmppVersion},
hold = Hold,
wait = Wait,
version = Version
})
end),
handle_http_put(Sid, Rid, Attrs, Payload, true, IP).
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
%%% 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.