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

Convert to exmpp.

The admin web interface is working but HTTP polling seems broken in the
trunk.

PR:		EJABP-1

SVN Revision: 1654
This commit is contained in:
Jean-Sébastien Pédron 2008-10-13 15:36:43 +00:00
parent a94caf218f
commit 50b1e4c36f
6 changed files with 424 additions and 469 deletions

View File

@ -1,3 +1,10 @@
2008-10-13 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
* src/web/ejabberd_http.erl, src/web/ejabberd_http_poll.erl,
src/web/ejabberd_web.erl, src/web/ejabberd_web_admin.erl,
src/web/ejabberd_web_admin.hrl: Convert to exmpp. The admin web
interface is working but HTTP polling seems broken in the trunk.
2008-10-13 Jean-Sébastien Pédron <js.pedron@meetic-corp.com> 2008-10-13 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
Merge from trunk (r1613 to 1649). Merge from trunk (r1613 to 1649).

View File

@ -35,8 +35,9 @@
receive_headers/1, receive_headers/1,
url_encode/1]). url_encode/1]).
-include_lib("exmpp/include/exmpp.hrl").
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("jlib.hrl").
-include("ejabberd_http.hrl"). -include("ejabberd_http.hrl").
-record(state, {sockmod, -record(state, {sockmod,
@ -202,7 +203,7 @@ process_header(State, Data) ->
request_path = Path, request_path = Path,
request_keepalive = KeepAlive}; request_keepalive = KeepAlive};
{ok, {http_header, _, 'Connection', _, Conn}} -> {ok, {http_header, _, 'Connection', _, Conn}} ->
KeepAlive1 = case jlib:tolower(Conn) of KeepAlive1 = case exmpp_stringprep:to_lower(Conn) of
"keep-alive" -> "keep-alive" ->
true; true;
"close" -> "close" ->
@ -349,10 +350,9 @@ process_request(#state{request_method = Method,
%% procedure (process) that handles dispatching based on %% procedure (process) that handles dispatching based on
%% URL path prefix. %% URL path prefix.
case process(RequestHandlers, Request) of case process(RequestHandlers, Request) of
El when element(1, El) == xmlelement -> El when is_record(El, xmlel) ->
make_xhtml_output(State, 200, [], El); make_xhtml_output(State, 200, [], El);
{Status, Headers, El} when {Status, Headers, El} when is_record(El, xmlel) ->
element(1, El) == xmlelement ->
make_xhtml_output(State, Status, Headers, El); make_xhtml_output(State, Status, Headers, El);
Output when is_list(Output) or is_binary(Output) -> Output when is_list(Output) or is_binary(Output) ->
make_text_output(State, 200, [], Output); make_text_output(State, 200, [], Output);
@ -412,10 +412,9 @@ process_request(#state{request_method = Method,
headers = RequestHeaders, headers = RequestHeaders,
ip = IP}, ip = IP},
case process(RequestHandlers, Request) of case process(RequestHandlers, Request) of
El when element(1, El) == xmlelement -> El when is_record(El, xmlel) ->
make_xhtml_output(State, 200, [], El); make_xhtml_output(State, 200, [], El);
{Status, Headers, El} when {Status, Headers, El} when is_record(El, xmlel) ->
element(1, El) == xmlelement ->
make_xhtml_output(State, Status, Headers, El); make_xhtml_output(State, Status, Headers, El);
Output when is_list(Output) or is_binary(Output) -> Output when is_list(Output) or is_binary(Output) ->
make_text_output(State, 200, [], Output); make_text_output(State, 200, [], Output);
@ -428,8 +427,8 @@ process_request(State) ->
make_xhtml_output(State, make_xhtml_output(State,
400, 400,
[], [],
ejabberd_web:make_xhtml([{xmlelement, "h1", [], ejabberd_web:make_xhtml([#xmlel{ns = ?NS_XHTML, name = 'h1', children =
[{xmlcdata, "400 Bad Request"}]}])). [#xmlcdata{cdata = <<"400 Bad Request">>}]}])).
recv_data(State, Len) -> recv_data(State, Len) ->
@ -459,10 +458,10 @@ make_xhtml_output(State, Status, Headers, XHTML) ->
Data = case lists:member(html, Headers) of Data = case lists:member(html, Headers) of
true -> true ->
list_to_binary([?HTML_DOCTYPE, list_to_binary([?HTML_DOCTYPE,
element_to_string(XHTML)]); exmpp_xml:document_to_list(exmpp_xml:indent_document(XHTML, <<>>))]);
_ -> _ ->
list_to_binary([?XHTML_DOCTYPE, list_to_binary([?XHTML_DOCTYPE,
element_to_string(XHTML)]) exmpp_xml:document_to_list(exmpp_xml:indent_document(XHTML, <<>>))])
end, end,
Headers1 = case lists:keysearch("Content-Type", 1, Headers) of Headers1 = case lists:keysearch("Content-Type", 1, Headers) of
{value, _} -> {value, _} ->
@ -544,40 +543,6 @@ parse_lang(Langs) ->
"en" "en"
end. end.
element_to_string(El) ->
case El of
{xmlelement, Name, Attrs, Els} ->
if
Els /= [] ->
[$<, Name, attrs_to_list(Attrs), $>,
[element_to_string(E) || E <- Els],
$<, $/, Name, $>];
true ->
[$<, Name, attrs_to_list(Attrs), $/, $>]
end;
{xmlcdata, CData} ->
crypt(CData)
end.
attrs_to_list(Attrs) ->
[attr_to_list(A) || A <- Attrs].
attr_to_list({Name, Value}) ->
[$\s, crypt(Name), $=, $", crypt(Value), $"].
crypt(S) when is_list(S) ->
[case C of
$& -> "&amp;";
$< -> "&lt;";
$> -> "&gt;";
$" -> "&quot;";
$' -> "&#39;";
_ -> C
end || C <- S];
crypt(S) when is_binary(S) ->
crypt(binary_to_list(S)).
% Code below is taken (with some modifications) from the yaws webserver, which % Code below is taken (with some modifications) from the yaws webserver, which
% is distributed under the folowing license: % is distributed under the folowing license:
% %

View File

@ -44,8 +44,9 @@
close/1, close/1,
process/2]). process/2]).
-include_lib("exmpp/include/exmpp.hrl").
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("jlib.hrl").
-include("ejabberd_http.hrl"). -include("ejabberd_http.hrl").
-record(http_poll, {id, pid}). -record(http_poll, {id, pid}).
@ -71,6 +72,11 @@
-define(CT, {"Content-Type", "text/xml; charset=utf-8"}). -define(CT, {"Content-Type", "text/xml; charset=utf-8"}).
-define(BAD_REQUEST, [?CT, {"Set-Cookie", "ID=-3:0; expires=-1"}]). -define(BAD_REQUEST, [?CT, {"Set-Cookie", "ID=-3:0; expires=-1"}]).
-define(PARSER_OPTIONS, [
{namespace, true},
{name_as_atom, true},
{autoload_known, true}
]).
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
%%% API %%% API
@ -156,8 +162,8 @@ process([], #request{data = Data,
{200, [?CT, {"Set-Cookie", "ID=-2:0; expires=-1"}], ""} {200, [?CT, {"Set-Cookie", "ID=-2:0; expires=-1"}], ""}
end; end;
process(_, _Request) -> process(_, _Request) ->
{400, [], {xmlelement, "h1", [], {400, [], #xmlel{ns = ?NS_XHTML, name = 'h1', children =
[{xmlcdata, "400 Bad Request"}]}}. [#xmlcdata{cdata = <<"400 Bad Request">>}]}}.
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
%%% Callback functions from gen_fsm %%% Callback functions from gen_fsm
@ -397,7 +403,7 @@ resend_messages(Messages) ->
%% This function is used to resend messages that have been polled but not %% This function is used to resend messages that have been polled but not
%% delivered. %% delivered.
resend_message(Packet) -> resend_message(Packet) ->
ParsedPacket = xml_stream:parse_element(Packet), [ParsedPacket] = exmpp_xml:parse_document(Packet, ?PARSER_OPTIONS),
From = get_jid("from", ParsedPacket), From = get_jid("from", ParsedPacket),
To = get_jid("to", ParsedPacket), To = get_jid("to", ParsedPacket),
?DEBUG("Resend ~p ~p ~p~n",[From,To, ParsedPacket]), ?DEBUG("Resend ~p ~p ~p~n",[From,To, ParsedPacket]),
@ -405,10 +411,17 @@ resend_message(Packet) ->
%% Type can be "from" or "to" %% Type can be "from" or "to"
%% Parsed packet is a parsed Jabber packet. %% Parsed packet is a parsed Jabber packet.
get_jid(Type, ParsedPacket) -> get_jid("from", ParsedPacket) ->
case xml:get_tag_attr(Type, ParsedPacket) of case exmpp_stanza:get_sender(ParsedPacket) of
{value, StringJid} -> undefined ->
jlib:string_to_jid(StringJid); #jid{};
false -> From ->
jlib:make_jid("","","") exmpp_jid:list_to_jid(From)
end;
get_jid("to", ParsedPacket) ->
case exmpp_stanza:get_recipient(ParsedPacket) of
undefined ->
#jid{};
From ->
exmpp_jid:list_to_jid(From)
end. end.

View File

@ -31,8 +31,9 @@
-export([make_xhtml/1, make_xhtml/2, -export([make_xhtml/1, make_xhtml/2,
error/1]). error/1]).
-include_lib("exmpp/include/exmpp.hrl").
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("jlib.hrl").
-include("ejabberd_http.hrl"). -include("ejabberd_http.hrl").
@ -45,36 +46,40 @@ make_xhtml(Els) ->
make_xhtml([], Els). make_xhtml([], Els).
make_xhtml(HeadEls, Els) -> make_xhtml(HeadEls, Els) ->
{xmlelement, "html", [{"xmlns", "http://www.w3.org/1999/xhtml"}, #xmlel{ns = ?NS_XHTML, name = 'html', attrs = [
{"xml:lang", "en"}, #xmlattr{ns = ?NS_XML, name = 'lang', value = "en"},
{"lang", "en"}], #xmlattr{name = 'lang', value = "en"}], children = [
[{xmlelement, "head", [], #xmlel{ns = ?NS_XHTML, name = 'head', children = [
[{xmlelement, "meta", [{"http-equiv", "Content-Type"}, #xmlel{ns = ?NS_XHTML, name = 'meta', attrs = [
{"content", "text/html; charset=utf-8"}], []} #xmlattr{name = 'http-equiv', value = "Content-Type"},
| HeadEls]}, #xmlattr{name = 'content', value = "text/html; charset=utf-8"}
{xmlelement, "body", [], Els} ]}
| HeadEls
]},
#xmlel{ns = ?NS_XHTML, name = 'body', children = Els}
]}. ]}.
-define(X(Name), {xmlelement, Name, [], []}). -define(X(Name), #xmlel{ns = ?NS_XHTML, name = Name}).
-define(XA(Name, Attrs), {xmlelement, Name, Attrs, []}). -define(XA(Name, Attrs), #xmlel{ns = ?NS_XHTML, name = Name, attrs = Attrs}).
-define(XE(Name, Els), {xmlelement, Name, [], Els}). -define(XE(Name, Els), #xmlel{ns = ?NS_XHTML, name = Name, children = Els}).
-define(XAE(Name, Attrs, Els), {xmlelement, Name, Attrs, Els}). -define(XAE(Name, Attrs, Els), #xmlel{ns = ?NS_XHTML, name = Name,
-define(C(Text), {xmlcdata, Text}). attrs = Attrs, children = Els}).
-define(C(Text), #xmlcdata{cdata = list_to_binary(Text)}).
-define(XC(Name, Text), ?XE(Name, [?C(Text)])). -define(XC(Name, Text), ?XE(Name, [?C(Text)])).
-define(XAC(Name, Attrs, Text), ?XAE(Name, Attrs, [?C(Text)])). -define(XAC(Name, Attrs, Text), ?XAE(Name, Attrs, [?C(Text)])).
-define(LI(Els), ?XE("li", Els)). -define(LI(Els), ?XE('li', Els)).
-define(A(URL, Els), ?XAE("a", [{"href", URL}], Els)). -define(A(URL, Els), ?XAE('a', [#xmlattr{name = 'href', value = URL}], Els)).
-define(AC(URL, Text), ?A(URL, [?C(Text)])). -define(AC(URL, Text), ?A(URL, [?C(Text)])).
-define(P, ?X("p")). -define(P, ?X('p')).
-define(BR, ?X("br")). -define(BR, ?X('br')).
-define(INPUT(Type, Name, Value), -define(INPUT(Type, Name, Value),
?XA("input", [{"type", Type}, ?XA('input', [#xmlattr{name = 'type', value = Type},
{"name", Name}, #xmlattr{name = 'name', value = Name},
{"value", Value}])). #xmlattr{name = 'value', value = Value}])).
error(not_found) -> error(not_found) ->
{404, [], make_xhtml([?XC("h1", "404 Not Found")])}; {404, [], make_xhtml([?XC('h1', "404 Not Found")])};
error(not_allowed) -> error(not_allowed) ->
{401, [], make_xhtml([?XC("h1", "401 Unauthorized")])}. {401, [], make_xhtml([?XC('h1', "401 Unauthorized")])}.

File diff suppressed because it is too large Load Diff

View File

@ -19,11 +19,12 @@
%%% %%%
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
-define(X(Name), {xmlelement, Name, [], []}). -define(X(Name), #xmlel{ns = ?NS_XHTML, name = Name}).
-define(XA(Name, Attrs), {xmlelement, Name, Attrs, []}). -define(XA(Name, Attrs), #xmlel{ns = ?NS_XHTML, name = Name, attrs = Attrs}).
-define(XE(Name, Els), {xmlelement, Name, [], Els}). -define(XE(Name, Els), #xmlel{ns = ?NS_XHTML, name = Name, children = Els}).
-define(XAE(Name, Attrs, Els), {xmlelement, Name, Attrs, Els}). -define(XAE(Name, Attrs, Els), #xmlel{ns = ?NS_XHTML, name = Name,
-define(C(Text), {xmlcdata, Text}). attrs = Attrs, children = Els}).
-define(C(Text), #xmlcdata{cdata = list_to_binary(Text)}).
-define(XC(Name, Text), ?XE(Name, [?C(Text)])). -define(XC(Name, Text), ?XE(Name, [?C(Text)])).
-define(XAC(Name, Attrs, Text), ?XAE(Name, Attrs, [?C(Text)])). -define(XAC(Name, Attrs, Text), ?XAE(Name, Attrs, [?C(Text)])).
@ -32,21 +33,22 @@
-define(XCT(Name, Text), ?XC(Name, ?T(Text))). -define(XCT(Name, Text), ?XC(Name, ?T(Text))).
-define(XACT(Name, Attrs, Text), ?XAC(Name, Attrs, ?T(Text))). -define(XACT(Name, Attrs, Text), ?XAC(Name, Attrs, ?T(Text))).
-define(LI(Els), ?XE("li", Els)). -define(LI(Els), ?XE('li', Els)).
-define(A(URL, Els), ?XAE("a", [{"href", URL}], Els)). -define(A(URL, Els), ?XAE('a', [#xmlattr{name = 'href', value = URL}], Els)).
-define(AC(URL, Text), ?A(URL, [?C(Text)])). -define(AC(URL, Text), ?A(URL, [?C(Text)])).
-define(ACT(URL, Text), ?AC(URL, ?T(Text))). -define(ACT(URL, Text), ?AC(URL, ?T(Text))).
-define(P, ?X("p")). -define(P, ?X('p')).
-define(BR, ?X("br")). -define(BR, ?X('br')).
-define(INPUT(Type, Name, Value), -define(INPUT(Type, Name, Value),
?XA("input", [{"type", Type}, ?XA('input', [#xmlattr{name = 'type', value = Type},
{"name", Name}, #xmlattr{name = 'name', value = Name},
{"value", Value}])). #xmlattr{name = 'value', value = Value}])).
-define(INPUTT(Type, Name, Value), ?INPUT(Type, Name, ?T(Value))). -define(INPUTT(Type, Name, Value), ?INPUT(Type, Name, ?T(Value))).
-define(INPUTS(Type, Name, Value, Size), -define(INPUTS(Type, Name, Value, Size),
?XA("input", [{"type", Type}, ?XA('input', [#xmlattr{name = 'type', value = Type},
{"name", Name}, #xmlattr{name = 'name', value = Name},
{"value", Value}, #xmlattr{name = 'value', value = Value},
{"size", Size}])). #xmlattr{name = 'size', value = Size}])).
-define(INPUTST(Type, Name, Value, Size), ?INPUT(Type, Name, ?T(Value), Size)). -define(INPUTST(Type, Name, Value, Size), ?INPUT(Type, Name, ?T(Value), Size)).
-define(ACLINPUT(Text), ?XE("td", [?INPUT("text", "value" ++ ID, Text)])). -define(ACLINPUT(Text), ?XE('td', [?INPUT("text", "value" ++ ID, Text)])).