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

Show informative webpage when browsing the HTTP-Poll page (EJAB-1106)

SVN Revision: 2752
This commit is contained in:
Badlop 2009-11-23 15:22:45 +00:00
parent 4dcfde7737
commit c1a7e30f12
2 changed files with 48 additions and 16 deletions

View File

@ -160,12 +160,34 @@ process([], #request{data = Data,
end end
end; end;
_ -> _ ->
{200, [?CT, {"Set-Cookie", "ID=-2:0; expires=-1"}], ""} HumanHTMLxmlel = get_human_html_xmlel(),
{200, [?CT, {"Set-Cookie", "ID=-2:0; expires=-1"}], HumanHTMLxmlel}
end; end;
process(_, _Request) -> process(_, _Request) ->
{400, [], #xmlel{ns = ?NS_XHTML, name = 'h1', children = {400, [], #xmlel{ns = ?NS_XHTML, name = 'h1', children =
[#xmlcdata{cdata = <<"400 Bad Request">>}]}}. [#xmlcdata{cdata = <<"400 Bad Request">>}]}}.
%% Code copied from mod_http_bind.erl and customized
get_human_html_xmlel() ->
Heading = "ejabberd " ++ atom_to_list(?MODULE),
H = #xmlel{name = h1, children = [#xmlcdata{cdata = Heading}]},
Par1 = #xmlel{name = p, children =
[#xmlcdata{cdata = <<"An implementation of ">>},
#xmlel{name = a,
attrs = [#xmlattr{name=href, value = <<"http://xmpp.org/extensions/xep-0025.html">>}],
children = [#xmlcdata{cdata = <<"Jabber HTTP Polling (XEP-0025)">>}]
}
]},
Par2 = #xmlel{name = p, children =
[#xmlcdata{cdata = <<"This web page is only informative. "
"To use HTTP-Poll you need a Jabber/XMPP client that supports it.">>}
]},
#xmlel{name = html,
attrs = [#xmlattr{name = xmlns, value= <<"http://www.w3.org/1999/xhtml">>}],
children =
[#xmlel{name = head, children = [#xmlel{name = title, children = [#xmlcdata{cdata = Heading}]}]},
#xmlel{name = body, children = [H, Par1, Par2]}]}.
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
%%% Callback functions from gen_fsm %%% Callback functions from gen_fsm
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------

View File

@ -45,6 +45,7 @@
process/2 process/2
]). ]).
-include_lib("exmpp/include/exmpp.hrl").
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("jlib.hrl"). -include("jlib.hrl").
-include("ejabberd_http.hrl"). -include("ejabberd_http.hrl").
@ -60,8 +61,8 @@
process([], #request{method = 'POST', process([], #request{method = 'POST',
data = []}) -> data = []}) ->
?DEBUG("Bad Request: no data", []), ?DEBUG("Bad Request: no data", []),
{400, [], {xmlelement, "h1", [], {400, [], #xmlel{name = h1, children =
[{xmlcdata, "400 Bad Request"}]}}; [#xmlcdata{cdata = <<"400 Bad Request">>}]}};
process([], #request{method = 'POST', process([], #request{method = 'POST',
data = Data, data = Data,
ip = IP}) -> ip = IP}) ->
@ -69,22 +70,31 @@ process([], #request{method = 'POST',
ejabberd_http_bind:process_request(Data, IP); ejabberd_http_bind:process_request(Data, IP);
process([], #request{method = 'GET', process([], #request{method = 'GET',
data = []}) -> data = []}) ->
Heading = "Ejabberd " ++ atom_to_list(?MODULE) ++ " v" ++ ?MOD_HTTP_BIND_VERSION, get_human_html_xmlel();
{xmlelement, "html", [{"xmlns", "http://www.w3.org/1999/xhtml"}],
[{xmlelement, "head", [],
[{xmlelement, "title", [], [{xmlcdata, Heading}]}]},
{xmlelement, "body", [],
[{xmlelement, "h1", [], [{xmlcdata, Heading}]},
{xmlelement, "p", [],
[{xmlcdata, "An implementation of "},
{xmlelement, "a", [{"href", "http://www.xmpp.org/extensions/xep-0206.html"}],
[{xmlcdata, "XMPP over BOSH (XEP-0206)"}]}]}
]}]};
process(_Path, _Request) -> process(_Path, _Request) ->
?DEBUG("Bad Request: ~p", [_Request]), ?DEBUG("Bad Request: ~p", [_Request]),
{400, [], {xmlelement, "h1", [], {400, [], #xmlel{name = h1, children =
[{xmlcdata, "400 Bad Request"}]}}. [#xmlcdata{cdata = <<"400 Bad Request">>}]}}.
get_human_html_xmlel() ->
Heading = "ejabberd " ++ atom_to_list(?MODULE) ++ " v" ++ ?MOD_HTTP_BIND_VERSION,
H = #xmlel{name = h1, children = [#xmlcdata{cdata = Heading}]},
Par1 = #xmlel{name = p, children =
[#xmlcdata{cdata = <<"An implementation of ">>},
#xmlel{name = a,
attrs = [#xmlattr{name=href, value = <<"http://xmpp.org/extensions/xep-0206.html">>}],
children = [#xmlcdata{cdata = <<"XMPP over BOSH (XEP-0206)">>}]
}
]},
Par2 = #xmlel{name = p, children =
[#xmlcdata{cdata = <<"This web page is only informative. "
"To use HTTP-Bind you need a Jabber/XMPP client that supports it.">>}
]},
#xmlel{name = html,
attrs = [#xmlattr{name = xmlns, value= <<"http://www.w3.org/1999/xhtml">>}],
children =
[#xmlel{name = head, children = [#xmlel{name = title, children = [#xmlcdata{cdata = Heading}]}]},
#xmlel{name = body, children = [H, Par1, Par2]}]}.
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
%%% BEHAVIOUR CALLBACKS %%% BEHAVIOUR CALLBACKS