2004-03-02 22:16:55 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : ejabberd_web.erl
|
|
|
|
%%% Author : Alexey Shchepin <alexey@sevcom.net>
|
2007-06-27 13:05:14 +02:00
|
|
|
%%% Purpose :
|
2004-03-02 22:16:55 +01:00
|
|
|
%%% Created : 28 Feb 2004 by Alexey Shchepin <alexey@sevcom.net>
|
|
|
|
%%% Id : $Id$
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(ejabberd_web).
|
|
|
|
-author('alexey@sevcom.net').
|
2006-02-03 04:28:15 +01:00
|
|
|
-vsn('$Revision$ ').
|
2004-03-02 22:16:55 +01:00
|
|
|
|
|
|
|
%% External exports
|
|
|
|
-export([make_xhtml/1,
|
2007-01-25 06:53:58 +01:00
|
|
|
error/1]).
|
2004-03-02 22:16:55 +01:00
|
|
|
|
|
|
|
-include("ejabberd.hrl").
|
|
|
|
-include("jlib.hrl").
|
2004-03-04 21:56:32 +01:00
|
|
|
-include("ejabberd_http.hrl").
|
2004-03-02 22:16:55 +01:00
|
|
|
|
|
|
|
|
2007-01-25 06:53:58 +01:00
|
|
|
%% XXX bard: there are variants of make_xhtml in ejabberd_http and
|
|
|
|
%% ejabberd_web_admin. It might be a good idea to centralize it here
|
|
|
|
%% and also create an ejabberd_web.hrl file holding the macros, so
|
|
|
|
%% that third parties can use ejabberd_web as an "utility" library.
|
|
|
|
|
2004-03-02 22:16:55 +01:00
|
|
|
make_xhtml(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"}], []}]},
|
|
|
|
{xmlelement, "body", [], 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(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(AC(URL, Text), ?A(URL, [?C(Text)])).
|
|
|
|
-define(P, ?X("p")).
|
|
|
|
-define(BR, ?X("br")).
|
2004-03-21 21:27:09 +01:00
|
|
|
-define(INPUT(Type, Name, Value),
|
|
|
|
?XA("input", [{"type", Type},
|
|
|
|
{"name", Name},
|
|
|
|
{"value", Value}])).
|
2004-03-03 22:07:27 +01:00
|
|
|
|
2007-01-25 06:53:58 +01:00
|
|
|
error(not_found) ->
|
|
|
|
{404, [], make_xhtml([?XC("h1", "404 Not Found")])};
|
2007-06-27 13:05:14 +02:00
|
|
|
error(not_allowed) ->
|
|
|
|
{401, [], make_xhtml([?XC("h1", "401 Unauthorized")])}.
|