Skip to content

Commit

Permalink
Merge git://github.com/klacke/yaws into auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Alenius committed May 31, 2009
2 parents dc206fd + d781406 commit c60f1e6
Show file tree
Hide file tree
Showing 20 changed files with 203 additions and 176 deletions.
2 changes: 1 addition & 1 deletion scripts/debian/yaws.init.d
Expand Up @@ -14,7 +14,7 @@ prog=yaws
# By default we run with the default id
# idopts=--id myserverid

conf="--conf %etcdir%/yaws.conf"
conf="--conf %etcdir%/yaws/yaws.conf"

test -x $yaws || exit 1

Expand Down
2 changes: 1 addition & 1 deletion scripts/freebsd/yaws.sh
Expand Up @@ -6,7 +6,7 @@
YAWS_BIN=%prefix%bin/yaws
# By default we run with the default id
# YAWS_ID=myserverid
CONF=%etcdir%yaws.conf
CONF=%etcdir%yaws/yaws.conf


if [ "x${YAWS_ID}" = x ]; then
Expand Down
2 changes: 2 additions & 0 deletions scripts/make-release
Expand Up @@ -44,8 +44,10 @@ ln -s $NAME_VERSION tmp/yaws

echo release resides in `pwd`/$NAME_VERSION.tar.gz
echo release resides in `pwd`/yaws/win32/Yaws-${YAWS_VSN}-windows-installer.exe

echo "To push this do:"
echo "git push origin revs/tags/yaws-${version}:revs/tags/yaws-${version}"
echo "ehhh or git push --tags"


exit 0
Expand Down
2 changes: 1 addition & 1 deletion scripts/netbsd/yaws.sh
Expand Up @@ -20,7 +20,7 @@ fi
name="yaws"
rcvar=$name
yaws_command="%prefix%bin/${name}"
required_files="%etcdir%yaws.conf"
required_files="%etcdir%yaws/yaws.conf"

start_cmd="yaws_start"
stop_cmd="yaws_stop"
Expand Down
2 changes: 1 addition & 1 deletion scripts/redhat/yaws.init.d
Expand Up @@ -20,7 +20,7 @@ prog=yaws
#
yawsid=default
#yawsid_opts="--id $yawsid"
conf="--conf %etcdir%yaws.conf"
conf="--conf %etcdir%yaws/yaws.conf"

start() {
echo -n $"Starting $prog: "
Expand Down
2 changes: 1 addition & 1 deletion scripts/suse/yaws.init.d
Expand Up @@ -6,7 +6,7 @@ YAWS_BIN=%prefix%bin/yaws
## By default we run with the default id
# YAWS_ID_OPTS=--id myserverid

conf="--conf %etcdir%/yaws.conf"
conf="--conf %etcdir%yaws/yaws.conf"

test -x $YAWS_BIN || exit 5

Expand Down
6 changes: 5 additions & 1 deletion scripts/yaws.template
Expand Up @@ -9,7 +9,11 @@ to_erl="%to_erl%"
# erlexec requires HOME to be set, and some distros
# run /etc/rc scripts without HOME being set
if [ -z "$HOME" ]; then
export HOME=/root
if [ `id u` = 0 -a -d /root ]; then
export HOME=/root
else
export HOME=/tmp
fi
fi

case `uname` in
Expand Down
40 changes: 19 additions & 21 deletions src/yaws.erl
Expand Up @@ -464,11 +464,10 @@ local_time_as_gmt_string(LocalTime) ->
time_to_string(erlang:localtime_to_universaltime(LocalTime),"GMT").


time_to_string( {{Year, Month, Day}, {Hour, Min, Sec}}, Zone) ->
io_lib:format("~s, ~s ~s ~w ~s:~s:~s ~s",
[day(Year, Month, Day),
mk2(Day), month(Month), Year,
mk2(Hour), mk2(Min), mk2(Sec), Zone]).
time_to_string({{Year, Month, Day}, {Hour, Min, Sec}}, Zone) ->
[day(Year, Month, Day), ", ",
mk2(Day), " ", month(Month), " ", integer_to_list(Year), " ",
mk2(Hour), ":", mk2(Min), ":", mk2(Sec), " ", Zone].



Expand Down Expand Up @@ -1344,22 +1343,21 @@ pack_bin(<<_:6,A:6,B:6,C:6,D:6,E:6,F:6,G:6,H:6,I:6,J:6,K:6>>) ->

%% Like Base64 for no particular reason.
pc(X) when X >= 0, X < 26 ->
X + $A;
pc(X) when X >= 26, X < 52 ->
X - 26 + $a;
pc(X) when X >= 52, X < 62 ->
X - 52 + $0;
pc(62) ->
$+;
pc(63) ->
$/.



make_content_type_header(no_content_type) ->
undefined;
make_content_type_header(MimeType) ->
["Content-Type: ", MimeType, "\r\n"].
X + $A;
pc(X) when X >= 26, X < 52 ->
X - 26 + $a;
pc(X) when X >= 52, X < 62 ->
X - 52 + $0;
pc(62) ->
$+;
pc(63) ->
$/.


make_content_type_header(no_content_type) ->
undefined;
make_content_type_header(MimeType) ->
["Content-Type: ", MimeType, "\r\n"].


make_content_range_header(all) ->
Expand Down
2 changes: 1 addition & 1 deletion src/yaws_api.erl
Expand Up @@ -1761,7 +1761,7 @@ sanitize_file_name([]) ->

%% to be used in embedded mode, make it possible
%% to pass a config to yaws from another data source
%% than /etc/yaws.conf, for example from a database
%% than /etc/yaws/yaws.conf, for example from a database
%% this code is also called by the server -h hup code
setconf(GC0, Groups0) ->
setconf(GC0, Groups0, true).
Expand Down
4 changes: 2 additions & 2 deletions src/yaws_config.erl
Expand Up @@ -32,11 +32,11 @@
paths() ->
case yaws:getuid() of
{ok, "0"} -> %% root
[yaws_generated:etcdir() ++ "/yaws.conf"];
[yaws_generated:etcdir() ++ "/yaws/yaws.conf"];
_ -> %% developer
[filename:join([yaws:home(), "yaws.conf"]),
"./yaws.conf",
yaws_generated:etcdir() ++ "/yaws.conf"]
yaws_generated:etcdir() ++ "/yaws/yaws.conf"]
end.


Expand Down
136 changes: 70 additions & 66 deletions src/yaws_server.erl
Expand Up @@ -806,7 +806,7 @@ ssl_listen_opts(GC, SSL) ->
if ?gc_use_old_ssl(GC) ->
false;
true ->
%{ssl_imp, new} .... doesn't work yet
%%{ssl_imp, new} - still doesn't work (R13B)
false
end
],
Expand Down Expand Up @@ -2043,6 +2043,7 @@ deliver_options(CliSock, _Req, Options) ->
doclose = false,
chunked = false,
server = yaws:make_server_header(),
date = yaws:make_date_header(),
allow = yaws:make_allow_header(Options)},
put(outh, H),
deliver_accumulated(CliSock),
Expand Down Expand Up @@ -3292,7 +3293,12 @@ cache_size(_UT) ->



cache_file(SC, GC, Path, UT)
cache_file(SC, GC, Path, UT)
when GC#gconf.max_num_cached_files == 0;
GC#gconf.max_num_cached_bytes == 0;
GC#gconf.max_size_cached_file == 0 ->
UT;
cache_file(SC, GC, Path, UT)
when ((UT#urltype.type == regular) or
((UT#urltype.type == yaws) and (UT#urltype.pathinfo == undefined))) ->
E = SC#sconf.ets,
Expand All @@ -3307,6 +3313,7 @@ cache_file(SC, GC, Path, UT)
cleanup_cache(E, num),
cache_file(SC, GC, Path, UT);
FI#file_info.size < GC#gconf.max_size_cached_file,
FI#file_info.size < GC#gconf.max_num_cached_bytes,
B + FI#file_info.size > GC#gconf.max_num_cached_bytes ->
error_logger:info_msg("Max size cached bytes reached for server "
"~p", [SC#sconf.servername]),
Expand All @@ -3315,7 +3322,8 @@ cache_file(SC, GC, Path, UT)
true ->
?Debug("Check file size\n",[]),
if
FI#file_info.size > GC#gconf.max_size_cached_file ->
FI#file_info.size > GC#gconf.max_size_cached_file;
FI#file_info.size > GC#gconf.max_num_cached_bytes ->
?Debug("Too large\n",[]),
UT;
true ->
Expand Down Expand Up @@ -3385,7 +3393,7 @@ do_url_type(SC, GetPath, ArgDocroot, VirtualDir) ->
case GetPath of
_ when ?sc_has_dav(SC) ->
{Comps, RevFile} = comp_split(GetPath),
{_Type, Mime} = suffix_type(RevFile),
{_Type, _, Mime} = suffix_type(RevFile),

FullPath = construct_fullpath(ArgDocroot, GetPath, VirtualDir),

Expand All @@ -3403,13 +3411,11 @@ do_url_type(SC, GetPath, ArgDocroot, VirtualDir) ->
"/" -> %% special case
case lists:keysearch("/", 1, SC#sconf.appmods) of
{value, {_, Mod}} ->
#urltype{
type = appmod,
data = {Mod, []},
dir = "",
path = "",
fullpath = ArgDocroot
};
#urltype{type = appmod,
data = {Mod, []},
dir = "",
path = "",
fullpath = ArgDocroot};
_ ->
maybe_return_dir(ArgDocroot, GetPath, VirtualDir)
end;
Expand Down Expand Up @@ -3574,10 +3580,7 @@ do_comp_split([], Comps, Part) ->
%% whereas for the configuration entry </docs/stuff/myapp , myappAppmod>
%% the request /otherpath/myapp will not trigger the appmod.
%%
%% !todo - consider supporting 'compound' floating appmods.
%% e.g <stuff/myapp , someappmod> to match /somewhere/stuff/myapp/xyz
%% but not /somewhere/myapp/xyz
%%

active_appmod([], _RequestSegs) ->
false;
active_appmod(AppMods, RequestSegs) ->
Expand All @@ -3586,57 +3589,58 @@ active_appmod(AppMods, RequestSegs) ->
%% call to a local func - replace?)

%%Accumulator is of form {RequestSegs, {AppmodMountPoint,Mod}}
Matched = lists:foldl(
fun(Pair,Acc) ->
{Mount, Mod} = Pair,
{ReqSegs, {LongestSoFar, _}} = Acc,

MountSegs = string:tokens(Mount,"/"),
case lists:prefix(MountSegs,ReqSegs) of
true ->
case LongestSoFar of
[$/|_] ->
%%simple comparison of string length
%% (as opposed to number of segments)
%% should be ok here.
if length(Mount) >
length(LongestSoFar) ->
{ReqSegs, {Mount, Mod}};
true ->
Acc
end;
_ ->
%%existing match is 'floating' -
%% we trump it.

{ReqSegs, {Mount, Mod}}
end;
false ->
case LongestSoFar of
[$/|_] ->
%%There is already a match for an
%% 'anchored' (ie absolute path)
%% mount point.
%% floating appmod can't override.
Acc;
_ ->
%%check for 'floating' match
case lists:member(Mount, ReqSegs) of
true ->
%%!todo - review & document.
%%latest 'floating' match wins
%% if multiple match?
%% (order in config vs position
%% in request URI ?)

{ReqSegs, {Mount, Mod}};
false ->
Acc
end
end
end
end, {RequestSegs, {"",""}}, AppMods),

Matched =
lists:foldl(
fun(Pair,Acc) ->
{Mount, Mod} = Pair,
{ReqSegs, {LongestSoFar, _}} = Acc,

MountSegs = string:tokens(Mount,"/"),
case lists:prefix(MountSegs,ReqSegs) of
true ->
case LongestSoFar of
[$/|_] ->
%%simple comparison of string length
%% (as opposed to number of segments)
%% should be ok here.
if length(Mount) >
length(LongestSoFar) ->
{ReqSegs, {Mount, Mod}};
true ->
Acc
end;
_ ->
%%existing match is 'floating' -
%% we trump it.

{ReqSegs, {Mount, Mod}}
end;
false ->
case LongestSoFar of
[$/|_] ->
%%There is already a match for an
%% 'anchored' (ie absolute path)
%% mount point.
%% floating appmod can't override.
Acc;
_ ->
%%check for 'floating' match
case lists:member(Mount, ReqSegs) of
true ->
%%!todo - review & document.
%%latest 'floating' match wins
%% if multiple match?
%% (order in config vs position
%% in request URI ?)

{ReqSegs, {Mount, Mod}};
false ->
Acc
end
end
end
end, {RequestSegs, {"",""}}, AppMods),

case Matched of
{_RequestSegs, {"",""}} ->
%%no appmod corresponding specifically to this http_request.path
Expand Down
4 changes: 2 additions & 2 deletions test/support/include.mk.in
Expand Up @@ -21,7 +21,7 @@ setup:
@rm -rf logs 2> /dev/null
@mkdir logs

start:
start: setup
$(YTOP)/bin/yaws -sname test --daemon --id testid --conf ./yaws.conf
$(YTOP)/bin/yaws --id testid --wait-started

Expand All @@ -43,7 +43,7 @@ connect:
status:
$(YTOP)/bin/yaws --id testid --status
stop:
$(YTOP)/bin/yaws --id testid --stop
$(YTOP)/bin/yaws --id testid --stop || true

stdconf:
cat ../conf/stdconf.conf | \
Expand Down

0 comments on commit c60f1e6

Please sign in to comment.