Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/processone/ejabberd.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>2013-04-08 13:12:54 +0400
committerChristophe Romain <christophe.romain@process-one.net>2013-06-13 13:11:02 +0400
commit4d8f7706240a1603468968f47fc7b150b788d62f (patch)
tree92d55d789cc7ac979b3c9e161ffb7f908eba043a /src/ejabberd_web.erl
parent4f77348255a16982ffb494b684b061d34db27608 (diff)
Switch to rebar build tool
Use dynamic Rebar configuration Make iconv dependency optional Disable transient_supervisors compile option Add hipe compilation support Only compile ibrowse and lhttpc when needed Make it possible to generate an OTP application release Add --enable-debug compile option Add --enable-all compiler option Add --enable-tools configure option Add --with-erlang configure option. Add --enable-erlang-version-check configure option. Add lager support Improve the test suite
Diffstat (limited to 'src/ejabberd_web.erl')
-rw-r--r--src/ejabberd_web.erl106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/ejabberd_web.erl b/src/ejabberd_web.erl
new file mode 100644
index 000000000..70f62de7f
--- /dev/null
+++ b/src/ejabberd_web.erl
@@ -0,0 +1,106 @@
+%%%----------------------------------------------------------------------
+%%% File : ejabberd_web.erl
+%%% Author : Alexey Shchepin <alexey@process-one.net>
+%%% Purpose :
+%%% Purpose :
+%%% Created : 28 Feb 2004 by Alexey Shchepin <alexey@process-one.net>
+%%%
+%%%
+%%% ejabberd, Copyright (C) 2002-2013 ProcessOne
+%%%
+%%% This program is free software; you can redistribute it and/or
+%%% modify it under the terms of the GNU General Public License as
+%%% published by the Free Software Foundation; either version 2 of the
+%%% License, or (at your option) any later version.
+%%%
+%%% This program is distributed in the hope that it will be useful,
+%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
+%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+%%% General Public License for more details.
+%%%
+%%% You should have received a copy of the GNU General Public License
+%%% along with this program; if not, write to the Free Software
+%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+%%% 02111-1307 USA
+%%%
+%%%----------------------------------------------------------------------
+
+-module(ejabberd_web).
+
+-author('alexey@process-one.net').
+
+%% External exports
+-export([make_xhtml/1, make_xhtml/2, error/1]).
+
+-include("ejabberd.hrl").
+-include("logger.hrl").
+
+-include("jlib.hrl").
+
+-include("ejabberd_http.hrl").
+
+%% 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.
+
+make_xhtml(Els) -> make_xhtml([], Els).
+
+make_xhtml(HeadEls, Els) ->
+ #xmlel{name = <<"html">>,
+ attrs =
+ [{<<"xmlns">>, <<"http://www.w3.org/1999/xhtml">>},
+ {<<"xml:lang">>, <<"en">>}, {<<"lang">>, <<"en">>}],
+ children =
+ [#xmlel{name = <<"head">>, attrs = [],
+ children =
+ [#xmlel{name = <<"meta">>,
+ attrs =
+ [{<<"http-equiv">>, <<"Content-Type">>},
+ {<<"content">>,
+ <<"text/html; charset=utf-8">>}],
+ children = []}
+ | HeadEls]},
+ #xmlel{name = <<"body">>, attrs = [], children = Els}]}.
+
+-define(X(Name),
+ #xmlel{name = Name, attrs = [], children = []}).
+
+-define(XA(Name, Attrs),
+ #xmlel{name = Name, attrs = Attrs, children = []}).
+
+-define(XE(Name, Els),
+ #xmlel{name = Name, attrs = [], children = Els}).
+
+-define(XAE(Name, Attrs, Els),
+ #xmlel{name = Name, attrs = Attrs, children = 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">>)).
+
+-define(INPUT(Type, Name, Value),
+ ?XA(<<"input">>,
+ [{<<"type">>, Type}, {<<"name">>, Name},
+ {<<"value">>, Value}])).
+
+error(not_found) ->
+ {404, [],
+ make_xhtml([?XC(<<"h1">>, <<"404 Not Found">>)])};
+error(not_allowed) ->
+ {401, [],
+ make_xhtml([?XC(<<"h1">>, <<"401 Unauthorized">>)])}.