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:
parent
a94caf218f
commit
50b1e4c36f
@ -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>
|
||||
|
||||
Merge from trunk (r1613 to 1649).
|
||||
|
@ -35,8 +35,9 @@
|
||||
receive_headers/1,
|
||||
url_encode/1]).
|
||||
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("jlib.hrl").
|
||||
-include("ejabberd_http.hrl").
|
||||
|
||||
-record(state, {sockmod,
|
||||
@ -202,7 +203,7 @@ process_header(State, Data) ->
|
||||
request_path = Path,
|
||||
request_keepalive = KeepAlive};
|
||||
{ok, {http_header, _, 'Connection', _, Conn}} ->
|
||||
KeepAlive1 = case jlib:tolower(Conn) of
|
||||
KeepAlive1 = case exmpp_stringprep:to_lower(Conn) of
|
||||
"keep-alive" ->
|
||||
true;
|
||||
"close" ->
|
||||
@ -349,10 +350,9 @@ process_request(#state{request_method = Method,
|
||||
%% procedure (process) that handles dispatching based on
|
||||
%% URL path prefix.
|
||||
case process(RequestHandlers, Request) of
|
||||
El when element(1, El) == xmlelement ->
|
||||
El when is_record(El, xmlel) ->
|
||||
make_xhtml_output(State, 200, [], El);
|
||||
{Status, Headers, El} when
|
||||
element(1, El) == xmlelement ->
|
||||
{Status, Headers, El} when is_record(El, xmlel) ->
|
||||
make_xhtml_output(State, Status, Headers, El);
|
||||
Output when is_list(Output) or is_binary(Output) ->
|
||||
make_text_output(State, 200, [], Output);
|
||||
@ -412,10 +412,9 @@ process_request(#state{request_method = Method,
|
||||
headers = RequestHeaders,
|
||||
ip = IP},
|
||||
case process(RequestHandlers, Request) of
|
||||
El when element(1, El) == xmlelement ->
|
||||
El when is_record(El, xmlel) ->
|
||||
make_xhtml_output(State, 200, [], El);
|
||||
{Status, Headers, El} when
|
||||
element(1, El) == xmlelement ->
|
||||
{Status, Headers, El} when is_record(El, xmlel) ->
|
||||
make_xhtml_output(State, Status, Headers, El);
|
||||
Output when is_list(Output) or is_binary(Output) ->
|
||||
make_text_output(State, 200, [], Output);
|
||||
@ -428,8 +427,8 @@ process_request(State) ->
|
||||
make_xhtml_output(State,
|
||||
400,
|
||||
[],
|
||||
ejabberd_web:make_xhtml([{xmlelement, "h1", [],
|
||||
[{xmlcdata, "400 Bad Request"}]}])).
|
||||
ejabberd_web:make_xhtml([#xmlel{ns = ?NS_XHTML, name = 'h1', children =
|
||||
[#xmlcdata{cdata = <<"400 Bad Request">>}]}])).
|
||||
|
||||
|
||||
recv_data(State, Len) ->
|
||||
@ -459,10 +458,10 @@ make_xhtml_output(State, Status, Headers, XHTML) ->
|
||||
Data = case lists:member(html, Headers) of
|
||||
true ->
|
||||
list_to_binary([?HTML_DOCTYPE,
|
||||
element_to_string(XHTML)]);
|
||||
exmpp_xml:document_to_list(exmpp_xml:indent_document(XHTML, <<>>))]);
|
||||
_ ->
|
||||
list_to_binary([?XHTML_DOCTYPE,
|
||||
element_to_string(XHTML)])
|
||||
exmpp_xml:document_to_list(exmpp_xml:indent_document(XHTML, <<>>))])
|
||||
end,
|
||||
Headers1 = case lists:keysearch("Content-Type", 1, Headers) of
|
||||
{value, _} ->
|
||||
@ -544,40 +543,6 @@ parse_lang(Langs) ->
|
||||
"en"
|
||||
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
|
||||
$& -> "&";
|
||||
$< -> "<";
|
||||
$> -> ">";
|
||||
$" -> """;
|
||||
$' -> "'";
|
||||
_ -> 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
|
||||
% is distributed under the folowing license:
|
||||
%
|
||||
|
@ -44,8 +44,9 @@
|
||||
close/1,
|
||||
process/2]).
|
||||
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("jlib.hrl").
|
||||
-include("ejabberd_http.hrl").
|
||||
|
||||
-record(http_poll, {id, pid}).
|
||||
@ -71,6 +72,11 @@
|
||||
-define(CT, {"Content-Type", "text/xml; charset=utf-8"}).
|
||||
-define(BAD_REQUEST, [?CT, {"Set-Cookie", "ID=-3:0; expires=-1"}]).
|
||||
|
||||
-define(PARSER_OPTIONS, [
|
||||
{namespace, true},
|
||||
{name_as_atom, true},
|
||||
{autoload_known, true}
|
||||
]).
|
||||
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% API
|
||||
@ -156,8 +162,8 @@ process([], #request{data = Data,
|
||||
{200, [?CT, {"Set-Cookie", "ID=-2:0; expires=-1"}], ""}
|
||||
end;
|
||||
process(_, _Request) ->
|
||||
{400, [], {xmlelement, "h1", [],
|
||||
[{xmlcdata, "400 Bad Request"}]}}.
|
||||
{400, [], #xmlel{ns = ?NS_XHTML, name = 'h1', children =
|
||||
[#xmlcdata{cdata = <<"400 Bad Request">>}]}}.
|
||||
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% 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
|
||||
%% delivered.
|
||||
resend_message(Packet) ->
|
||||
ParsedPacket = xml_stream:parse_element(Packet),
|
||||
[ParsedPacket] = exmpp_xml:parse_document(Packet, ?PARSER_OPTIONS),
|
||||
From = get_jid("from", ParsedPacket),
|
||||
To = get_jid("to", ParsedPacket),
|
||||
?DEBUG("Resend ~p ~p ~p~n",[From,To, ParsedPacket]),
|
||||
@ -405,10 +411,17 @@ resend_message(Packet) ->
|
||||
|
||||
%% Type can be "from" or "to"
|
||||
%% Parsed packet is a parsed Jabber packet.
|
||||
get_jid(Type, ParsedPacket) ->
|
||||
case xml:get_tag_attr(Type, ParsedPacket) of
|
||||
{value, StringJid} ->
|
||||
jlib:string_to_jid(StringJid);
|
||||
false ->
|
||||
jlib:make_jid("","","")
|
||||
get_jid("from", ParsedPacket) ->
|
||||
case exmpp_stanza:get_sender(ParsedPacket) of
|
||||
undefined ->
|
||||
#jid{};
|
||||
From ->
|
||||
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.
|
||||
|
@ -31,8 +31,9 @@
|
||||
-export([make_xhtml/1, make_xhtml/2,
|
||||
error/1]).
|
||||
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("jlib.hrl").
|
||||
-include("ejabberd_http.hrl").
|
||||
|
||||
|
||||
@ -45,36 +46,40 @@ make_xhtml(Els) ->
|
||||
make_xhtml([], Els).
|
||||
|
||||
make_xhtml(HeadEls, Els) ->
|
||||
{xmlelement, "html", [{"xmlns", "http://www.w3.org/1999/xhtml"},
|
||||
{"xml:lang", "en"},
|
||||
{"lang", "en"}],
|
||||
[{xmlelement, "head", [],
|
||||
[{xmlelement, "meta", [{"http-equiv", "Content-Type"},
|
||||
{"content", "text/html; charset=utf-8"}], []}
|
||||
| HeadEls]},
|
||||
{xmlelement, "body", [], Els}
|
||||
#xmlel{ns = ?NS_XHTML, name = 'html', attrs = [
|
||||
#xmlattr{ns = ?NS_XML, name = 'lang', value = "en"},
|
||||
#xmlattr{name = 'lang', value = "en"}], children = [
|
||||
#xmlel{ns = ?NS_XHTML, name = 'head', children = [
|
||||
#xmlel{ns = ?NS_XHTML, name = 'meta', attrs = [
|
||||
#xmlattr{name = 'http-equiv', value = "Content-Type"},
|
||||
#xmlattr{name = 'content', value = "text/html; charset=utf-8"}
|
||||
]}
|
||||
| HeadEls
|
||||
]},
|
||||
#xmlel{ns = ?NS_XHTML, name = 'body', children = Els}
|
||||
]}.
|
||||
|
||||
|
||||
-define(X(Name), {xmlelement, Name, [], []}).
|
||||
-define(XA(Name, Attrs), {xmlelement, Name, Attrs, []}).
|
||||
-define(XE(Name, Els), {xmlelement, Name, [], Els}).
|
||||
-define(XAE(Name, Attrs, Els), {xmlelement, Name, Attrs, Els}).
|
||||
-define(C(Text), {xmlcdata, Text}).
|
||||
-define(X(Name), #xmlel{ns = ?NS_XHTML, name = Name}).
|
||||
-define(XA(Name, Attrs), #xmlel{ns = ?NS_XHTML, name = Name, attrs = Attrs}).
|
||||
-define(XE(Name, Els), #xmlel{ns = ?NS_XHTML, name = Name, children = Els}).
|
||||
-define(XAE(Name, Attrs, Els), #xmlel{ns = ?NS_XHTML, name = Name,
|
||||
attrs = Attrs, children = Els}).
|
||||
-define(C(Text), #xmlcdata{cdata = list_to_binary(Text)}).
|
||||
-define(XC(Name, Text), ?XE(Name, [?C(Text)])).
|
||||
-define(XAC(Name, Attrs, Text), ?XAE(Name, Attrs, [?C(Text)])).
|
||||
|
||||
-define(LI(Els), ?XE("li", Els)).
|
||||
-define(A(URL, Els), ?XAE("a", [{"href", URL}], Els)).
|
||||
-define(LI(Els), ?XE('li', Els)).
|
||||
-define(A(URL, Els), ?XAE('a', [#xmlattr{name = 'href', value = URL}], Els)).
|
||||
-define(AC(URL, Text), ?A(URL, [?C(Text)])).
|
||||
-define(P, ?X("p")).
|
||||
-define(BR, ?X("br")).
|
||||
-define(P, ?X('p')).
|
||||
-define(BR, ?X('br')).
|
||||
-define(INPUT(Type, Name, Value),
|
||||
?XA("input", [{"type", Type},
|
||||
{"name", Name},
|
||||
{"value", Value}])).
|
||||
?XA('input', [#xmlattr{name = 'type', value = Type},
|
||||
#xmlattr{name = 'name', value = Name},
|
||||
#xmlattr{name = 'value', value = Value}])).
|
||||
|
||||
error(not_found) ->
|
||||
{404, [], make_xhtml([?XC("h1", "404 Not Found")])};
|
||||
{404, [], make_xhtml([?XC('h1', "404 Not Found")])};
|
||||
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
@ -19,11 +19,12 @@
|
||||
%%%
|
||||
%%%----------------------------------------------------------------------
|
||||
|
||||
-define(X(Name), {xmlelement, Name, [], []}).
|
||||
-define(XA(Name, Attrs), {xmlelement, Name, Attrs, []}).
|
||||
-define(XE(Name, Els), {xmlelement, Name, [], Els}).
|
||||
-define(XAE(Name, Attrs, Els), {xmlelement, Name, Attrs, Els}).
|
||||
-define(C(Text), {xmlcdata, Text}).
|
||||
-define(X(Name), #xmlel{ns = ?NS_XHTML, name = Name}).
|
||||
-define(XA(Name, Attrs), #xmlel{ns = ?NS_XHTML, name = Name, attrs = Attrs}).
|
||||
-define(XE(Name, Els), #xmlel{ns = ?NS_XHTML, name = Name, children = Els}).
|
||||
-define(XAE(Name, Attrs, Els), #xmlel{ns = ?NS_XHTML, name = Name,
|
||||
attrs = Attrs, children = Els}).
|
||||
-define(C(Text), #xmlcdata{cdata = list_to_binary(Text)}).
|
||||
-define(XC(Name, Text), ?XE(Name, [?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(XACT(Name, Attrs, Text), ?XAC(Name, Attrs, ?T(Text))).
|
||||
|
||||
-define(LI(Els), ?XE("li", Els)).
|
||||
-define(A(URL, Els), ?XAE("a", [{"href", URL}], Els)).
|
||||
-define(LI(Els), ?XE('li', Els)).
|
||||
-define(A(URL, Els), ?XAE('a', [#xmlattr{name = 'href', value = URL}], Els)).
|
||||
-define(AC(URL, Text), ?A(URL, [?C(Text)])).
|
||||
-define(ACT(URL, Text), ?AC(URL, ?T(Text))).
|
||||
-define(P, ?X("p")).
|
||||
-define(BR, ?X("br")).
|
||||
-define(P, ?X('p')).
|
||||
-define(BR, ?X('br')).
|
||||
-define(INPUT(Type, Name, Value),
|
||||
?XA("input", [{"type", Type},
|
||||
{"name", Name},
|
||||
{"value", Value}])).
|
||||
?XA('input', [#xmlattr{name = 'type', value = Type},
|
||||
#xmlattr{name = 'name', value = Name},
|
||||
#xmlattr{name = 'value', value = Value}])).
|
||||
|
||||
-define(INPUTT(Type, Name, Value), ?INPUT(Type, Name, ?T(Value))).
|
||||
-define(INPUTS(Type, Name, Value, Size),
|
||||
?XA("input", [{"type", Type},
|
||||
{"name", Name},
|
||||
{"value", Value},
|
||||
{"size", Size}])).
|
||||
?XA('input', [#xmlattr{name = 'type', value = Type},
|
||||
#xmlattr{name = 'name', value = Name},
|
||||
#xmlattr{name = 'value', value = Value},
|
||||
#xmlattr{name = 'size', 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)])).
|
||||
|
Loading…
Reference in New Issue
Block a user