Browse files

addded configure option -with-defaultcharset

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@729 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
1 parent 704f81e commit 177f03b60c3fa15fcca22c7c2ce5c668bcd7e5da @klacke committed Jun 17, 2004
Showing with 106 additions and 58 deletions.
  1. +47 −38 configure
  2. +12 −0 configure.in
  3. +1 −0 include.mk.in
  4. +0 −1 include/yaws.hrl
  5. +6 −2 src/Makefile
  6. +28 −6 src/mime_type_c.erl
  7. +2 −2 src/yaws.erl
  8. +2 −1 src/yaws_revproxy.erl
  9. +8 −8 src/yaws_server.erl
View
85 configure
@@ -11,6 +11,8 @@
ac_help=
ac_default_prefix=/usr/local
# Any additions from configure.in:
+ac_help="$ac_help
+ --with-defaultcharset=String specify default charset, i.e UTF-8 "
# Initialize some variables set by options.
# The variables have the same names as the options, with
@@ -563,7 +565,7 @@ else { echo "configure: error: can not run $ac_config_sub" 1>&2; exit 1; }
fi
echo $ac_n "checking host system type""... $ac_c" 1>&6
-echo "configure:567: checking host system type" >&5
+echo "configure:569: checking host system type" >&5
host_alias=$host
case "$host_alias" in
@@ -584,7 +586,7 @@ host_os=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
echo "$ac_t""$host" 1>&6
echo $ac_n "checking target system type""... $ac_c" 1>&6
-echo "configure:588: checking target system type" >&5
+echo "configure:590: checking target system type" >&5
target_alias=$target
case "$target_alias" in
@@ -602,7 +604,7 @@ target_os=`echo $target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
echo "$ac_t""$target" 1>&6
echo $ac_n "checking build system type""... $ac_c" 1>&6
-echo "configure:606: checking build system type" >&5
+echo "configure:608: checking build system type" >&5
build_alias=$build
case "$build_alias" in
@@ -632,7 +634,7 @@ EOF
# Extract the first word of "erl", so it can be a program name with args.
set dummy erl; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:636: checking for $ac_word" >&5
+echo "configure:638: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_ERL'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@@ -667,7 +669,7 @@ fi
# Extract the first word of "erlc", so it can be a program name with args.
set dummy erlc; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:671: checking for $ac_word" >&5
+echo "configure:673: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_ERLC'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@@ -705,6 +707,22 @@ fi
+# Check whether --with-default-charset or --without-default-charset was given.
+if test "${with_default_charset+set}" = set; then
+ withval="$with_default_charset"
+ :
+fi
+
+
+
+if test "x$with_defaultcharset" = "x" ; then
+ DEFAULT_CHARSET=
+else
+ DEFAULT_CHARSET=${with_defaultcharset}
+fi
+
+
+
@@ -730,7 +748,7 @@ fi
# Extract the first word of "gcc", so it can be a program name with args.
set dummy gcc; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:734: checking for $ac_word" >&5
+echo "configure:752: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@@ -760,7 +778,7 @@ if test -z "$CC"; then
# Extract the first word of "cc", so it can be a program name with args.
set dummy cc; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:764: checking for $ac_word" >&5
+echo "configure:782: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@@ -811,7 +829,7 @@ fi
# Extract the first word of "cl", so it can be a program name with args.
set dummy cl; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:815: checking for $ac_word" >&5
+echo "configure:833: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@@ -843,7 +861,7 @@ fi
fi
echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6
-echo "configure:847: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
+echo "configure:865: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
ac_ext=c
# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
@@ -854,12 +872,12 @@ cross_compiling=$ac_cv_prog_cc_cross
cat > conftest.$ac_ext << EOF
-#line 858 "configure"
+#line 876 "configure"
#include "confdefs.h"
main(){return(0);}
EOF
-if { (eval echo configure:863: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:881: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
ac_cv_prog_cc_works=yes
# If we can't run a trivial program, we are probably using a cross compiler.
if (./conftest; exit) 2>/dev/null; then
@@ -885,12 +903,12 @@ if test $ac_cv_prog_cc_works = no; then
{ echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; }
fi
echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
-echo "configure:889: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "configure:907: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6
cross_compiling=$ac_cv_prog_cc_cross
echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6
-echo "configure:894: checking whether we are using GNU C" >&5
+echo "configure:912: checking whether we are using GNU C" >&5
if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@@ -899,7 +917,7 @@ else
yes;
#endif
EOF
-if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:903: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:921: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
ac_cv_prog_gcc=yes
else
ac_cv_prog_gcc=no
@@ -918,7 +936,7 @@ ac_test_CFLAGS="${CFLAGS+set}"
ac_save_CFLAGS="$CFLAGS"
CFLAGS=
echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6
-echo "configure:922: checking whether ${CC-cc} accepts -g" >&5
+echo "configure:940: checking whether ${CC-cc} accepts -g" >&5
if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@@ -950,7 +968,7 @@ else
fi
echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
-echo "configure:954: checking how to run the C preprocessor" >&5
+echo "configure:972: checking how to run the C preprocessor" >&5
# On Suns, sometimes $CPP names a directory.
if test -n "$CPP" && test -d "$CPP"; then
CPP=
@@ -965,13 +983,13 @@ else
# On the NeXT, cc -E runs the code through the compiler's parser,
# not just through cpp.
cat > conftest.$ac_ext <<EOF
-#line 969 "configure"
+#line 987 "configure"
#include "confdefs.h"
#include <assert.h>
Syntax Error
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:975: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:993: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
:
@@ -982,13 +1000,13 @@ else
rm -rf conftest*
CPP="${CC-cc} -E -traditional-cpp"
cat > conftest.$ac_ext <<EOF
-#line 986 "configure"
+#line 1004 "configure"
#include "confdefs.h"
#include <assert.h>
Syntax Error
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:992: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1010: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
:
@@ -999,13 +1017,13 @@ else
rm -rf conftest*
CPP="${CC-cc} -nologo -E"
cat > conftest.$ac_ext <<EOF
-#line 1003 "configure"
+#line 1021 "configure"
#include "confdefs.h"
#include <assert.h>
Syntax Error
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1009: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1027: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
:
@@ -1031,13 +1049,13 @@ echo "$ac_t""$CPP" 1>&6
if test $ac_cv_prog_gcc = yes; then
echo $ac_n "checking whether ${CC-cc} needs -traditional""... $ac_c" 1>&6
-echo "configure:1035: checking whether ${CC-cc} needs -traditional" >&5
+echo "configure:1053: checking whether ${CC-cc} needs -traditional" >&5
if eval "test \"`echo '$''{'ac_cv_prog_gcc_traditional'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
ac_pattern="Autoconf.*'x'"
cat > conftest.$ac_ext <<EOF
-#line 1041 "configure"
+#line 1059 "configure"
#include "confdefs.h"
#include <sgtty.h>
Autoconf TIOCGETP
@@ -1055,7 +1073,7 @@ rm -f conftest*
if test $ac_cv_prog_gcc_traditional = no; then
cat > conftest.$ac_ext <<EOF
-#line 1059 "configure"
+#line 1077 "configure"
#include "confdefs.h"
#include <termio.h>
Autoconf TCGETA
@@ -1135,7 +1153,7 @@ esac
echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6
-echo "configure:1139: checking whether ${MAKE-make} sets \${MAKE}" >&5
+echo "configure:1157: checking whether ${MAKE-make} sets \${MAKE}" >&5
set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
@@ -1173,7 +1191,7 @@ fi
# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
# ./install, which can be erroneously created by make from ./install.sh.
echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
-echo "configure:1177: checking for a BSD compatible install" >&5
+echo "configure:1195: checking for a BSD compatible install" >&5
if test -z "$INSTALL"; then
if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
@@ -1237,16 +1255,6 @@ EOF
;;
- *qnx*)
- cat >> condefs.h <<\EOF
-#define QNX 1
-EOF
- LD_SHARED="qcc -shared"
-
- LIBS="$LIBS -lsocket"
-
- ;;
-
*solaris*)
cat >> confdefs.h <<\EOF
#define SOLARIS 1
@@ -1284,7 +1292,7 @@ EOF
# Extract the first word of "werl", so it can be a program name with args.
set dummy werl; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1278: checking for $ac_word" >&5
+echo "configure:1296: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_WERL'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@@ -1493,6 +1501,7 @@ s%@build_vendor@%$build_vendor%g
s%@build_os@%$build_os%g
s%@ERL@%$ERL%g
s%@ERLC@%$ERLC%g
+s%@DEFAULT_CHARSET@%$DEFAULT_CHARSET%g
s%@ERL_DLL_LIB@%$ERL_DLL_LIB%g
s%@ERLDIR@%$ERLDIR%g
s%@CC@%$CC%g
View
12 configure.in
@@ -16,6 +16,18 @@ AC_SUBST(ERL)
AC_SUBST(ERLC)
+AC_ARG_WITH(default-charset,
+[ --with-defaultcharset=String specify default charset, i.e UTF-8 ])
+
+
+if test "x$with_defaultcharset" = "x" ; then
+ DEFAULT_CHARSET=
+else
+ DEFAULT_CHARSET=${with_defaultcharset}
+fi
+
+AC_SUBST(DEFAULT_CHARSET)
+
dnl ----------------------------------------------------------------------
dnl
dnl BT_ERL_LIB_VSN figures out version of an erlang application
View
1 include.mk.in
@@ -10,6 +10,7 @@ ERL=@ERL@
WERL=@WERL@
ERLC=@ERLC@
EMULATOR=beam
+DEFAULT_CHARSET=@DEFAULT_CHARSET@
ifdef debug
ERLC_FLAGS+=-Ddebug
View
1 include/yaws.hrl
@@ -56,7 +56,6 @@
max_size_cached_file = 8000,
large_file_chunk_size = 10240,
cache_refresh_secs = 30, % seconds (auto zero when debug)
- default_type = "text/html",
include_dir = [],
phpexe = "php",
yaws, %% server string
View
8 src/Makefile
@@ -49,14 +49,18 @@ yaws_vsn.erl: yaws_vsn.template ../vsn.mk
. ../vsn.mk; \
sed "s/%VSN%/${YAWS_VSN}/" < yaws_vsn.template > yaws_vsn.erl
-mime_types.erl: mime.types mime_type_c.erl
+
+charset.def:
+ echo -n $(DEFAULT_CHARSET) > charset.def
+
+mime_types.erl: mime.types mime_type_c.erl charset.def
erl -noshell -pa ../ebin -s mime_type_c compile
debug:
$(MAKE) TYPE=debug
clean:
- rm -f $(EBIN_FILES) yaws_vsn.erl
+ rm -f $(EBIN_FILES) yaws_vsn.erl charset.def mime_types.erl
install: all docsinstall
install -d $(INSTALLPREFIX)/lib/yaws/examples/ebin
View
34 src/mime_type_c.erl
@@ -9,6 +9,7 @@
-author('klacke@hyber.org').
-compile(export_all).
+
%% this module reads the mime.types file and creates
%% the mod mime_types.erl
%% default type is text/plain
@@ -22,6 +23,13 @@ compile() ->
c() ->
{ok, F} = file:open("mime.types", [read]),
io:format("Compiling mime.types ... > mime_types.erl ~n", []),
+ {ok, B} = file:read_file("charset.def"),
+ case string:strip(binary_to_list(B)) of
+ [] ->
+ put(charset, []);
+ CharSet ->
+ put(charset, ";charset=" ++ CharSet)
+ end,
T = ets:new(aa, [set, public]),
c(F, T, io:get_line(F, '')).
@@ -73,12 +81,12 @@ nonl([H|T]) ->
special(Fd, Ext, Type) ->
io:format(Fd, "t(~p) -> {~p, ~p};~n",
- [Ext, Type, "text/html"]).
+ [Ext, Type, "text/html" ++ get(charset)]).
revspecial(Fd, Ext, Type) ->
io:format(Fd, "revt(~p) -> {~p, ~p};~n",
- [lists:reverse(Ext), Type, "text/html"]).
+ [lists:reverse(Ext), Type, "text/html" ++ get(charset)]).
gen(T) ->
@@ -94,10 +102,17 @@ gen(T) ->
special(Fd, "PHP", php),
special(Fd, "CGI", cgi),
lists:foreach(
- fun({Ext, MT}) ->
+ fun({Ext, MT0}) ->
+ MT = case MT0 of
+ "text/" ++ _ ->
+ MT0 ++ get(charset);
+ _ ->
+ MT0
+ end,
io:format(Fd, "t(~p) -> {regular, ~p};~n", [nonl(Ext), MT])
end, L),
- io:format(Fd, "t(_) -> {regular, \"text/plain\"}.~n~n~n", []),
+ io:format(Fd, "t(_) -> {regular, \"text/plain" ++ get(charset)
+ ++ "\"}.~n~n~n", []),
@@ -107,12 +122,19 @@ gen(T) ->
revspecial(Fd, "PHP", php),
revspecial(Fd, "CGI", cgi),
lists:foreach(
- fun({Ext, MT}) ->
+ fun({Ext, MT0}) ->
+ MT = case MT0 of
+ "text/" ++ _ ->
+ MT0 ++ get(charset);
+ _ ->
+ MT0
+ end,
io:format(Fd, "revt(~p) -> {regular, ~p};~n",
[nonl(lists:reverse(Ext)), MT])
end, L),
io:format(Fd, "revt(_) -> {regular,
- \"text/plain\"}.~n~n~n", []).
+ \"text/plain" ++ get(charset) ++
+ "\"}.~n~n~n", []).
View
4 src/yaws.erl
@@ -1120,15 +1120,15 @@ outh_set_304_headers(Req, UT, Headers) ->
},
put(outh, H2).
-outh_set_dyn_headers(Req, Headers) ->
+outh_set_dyn_headers(Req, Headers, UT) ->
H = get(outh),
{DoClose, Chunked} = dcc(Req, Headers),
H2 = H#outh{
status = 200,
date = make_date_header(),
server = make_server_header(),
connection = make_connection_close_header(DoClose),
- content_type = make_content_type_header("text/html"),
+ content_type = make_content_type_header(UT#urltype.mime),
doclose = DoClose,
chunked = Chunked,
transfer_encoding =
View
3 src/yaws_revproxy.erl
@@ -64,7 +64,8 @@ init(CliSock, ARG, DecPath, QueryPart, {Prefix, URL}, N) ->
?Debug("Client=~p, Srv=~p", [P1, self()]),
ploop(Srv, Cli, GC, SC);
ERR ->
- yaws:outh_set_dyn_headers(ARG#arg.req, ARG#arg.headers),
+ yaws:outh_set_dyn_headers(ARG#arg.req, ARG#arg.headers,
+ #urltype{}),
yaws_server:deliver_dyn_part(
CliSock,
0, "404",
View
16 src/yaws_server.erl
@@ -1060,7 +1060,7 @@ handle_ut(CliSock, ARG, UT, N) ->
SC=get(sc),GC=get(gc),
case UT#urltype.type of
error ->
- yaws:outh_set_dyn_headers(Req, H),
+ yaws:outh_set_dyn_headers(Req, H, UT),
deliver_dyn_part(CliSock,
0, "404",
N,
@@ -1073,7 +1073,7 @@ handle_ut(CliSock, ARG, UT, N) ->
);
directory when ?sc_has_dir_listings(SC) ->
P = UT#urltype.dir,
- yaws:outh_set_dyn_headers(Req, H),
+ yaws:outh_set_dyn_headers(Req, H, UT),
yaws_ls:list_directory(ARG, CliSock, UT#urltype.data, P, Req);
directory ->
handle_ut(CliSock, ARG, #urltype{type = error}, N);
@@ -1126,16 +1126,16 @@ handle_ut(CliSock, ARG, UT, N) ->
end;
yaws ->
?Debug("~p~n", [?format_record(UT, urltype)]),
- yaws:outh_set_dyn_headers(Req, H),
+ yaws:outh_set_dyn_headers(Req, H, UT),
do_yaws(CliSock, ARG, UT, N);
forbidden ->
- yaws:outh_set_dyn_headers(Req, H),
+ yaws:outh_set_dyn_headers(Req, H, UT),
deliver_403(CliSock, Req);
redir ->
- yaws:outh_set_dyn_headers(Req, H),
+ yaws:outh_set_dyn_headers(Req, H, UT),
deliver_302(CliSock, Req, ARG, UT#urltype.path);
appmod ->
- yaws:outh_set_dyn_headers(Req, H),
+ yaws:outh_set_dyn_headers(Req, H, UT),
{Mod, PathData} = UT#urltype.data,
A2 = ARG#arg{appmoddata = PathData, % trail
appmod_prepath = UT#urltype.path}, % head
@@ -1148,7 +1148,7 @@ handle_ut(CliSock, ARG, UT, N) ->
end
);
cgi ->
- yaws:outh_set_dyn_headers(Req, H),
+ yaws:outh_set_dyn_headers(Req, H, UT),
deliver_dyn_part(CliSock,
0, "cgi",
N,
@@ -1160,7 +1160,7 @@ handle_ut(CliSock, ARG, UT, N) ->
end
);
php ->
- yaws:outh_set_dyn_headers(Req, H),
+ yaws:outh_set_dyn_headers(Req, H, UT),
deliver_dyn_part(CliSock,
0, "php",
N,

0 comments on commit 177f03b

Please sign in to comment.