Skip to content

Commit

Permalink
some more debug support
Browse files Browse the repository at this point in the history
git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@636 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information
Claes Wikstrom committed Mar 17, 2004
1 parent 985babd commit ffee7fc
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 59 deletions.
6 changes: 6 additions & 0 deletions src/yaws.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,12 @@ outh_serialize() ->
end,
StatusLine = ["HTTP/1.1 ", integer_to_list(Code), " ",
yaws_api:code_to_phrase(Code), "\r\n"],
GC=get(gc),
if ?gc_has_debug(GC) ->
yaws_debug:check_headers(H);
true ->
ok
end,
Headers = [noundef(H#outh.connection),
noundef(H#outh.server),
noundef(H#outh.location),
Expand Down
2 changes: 2 additions & 0 deletions src/yaws_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,8 @@ ehtml_expand({Tag, Attrs, Body}) when atom(Tag) ->
ehtml_expand([H|T]) -> [ehtml_expand(H)|ehtml_expand(T)];
ehtml_expand([]) -> [].



ehtml_attrs([]) -> [];
ehtml_attrs([Attribute|Tail]) when atom(Attribute) ->
[[$ |atom_to_list(Attribute)]|ehtml_attrs(Tail)];
Expand Down
2 changes: 1 addition & 1 deletion src/yaws_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ fload(FD, server_auth, GC, C, Cs, Lno, Chars, Auth) ->
case file:list_dir(Authdir) of
{ok,_} ->
error_logger:info_msg("Warning, authdir must be set "
"relative docroot ",[]);
"relative docroot ~n",[]);
_ ->
ok
end,
Expand Down
104 changes: 68 additions & 36 deletions src/yaws_debug.erl
Original file line number Diff line number Diff line change
Expand Up @@ -186,43 +186,75 @@ eprof() ->



%% not used
check_headers(L) ->
Hs = string:tokens(lists:flatten(L), "\r\n"),
io:format("XX ~p~n", [Hs]),
lists:foreach(
fun(H) ->
case lists:reverse(H) of
[_,_,$\r|_] ->
error_logger:error_msg("Bad header ~p, it contains"
" '\\r' or '\\n' at end ",
[lists:flatten(H)]),
exit(normal);
[_,_,$\n|_] ->
error_logger:error_msg("Bad header ~p, it contains"
" '\\r' or '\\n' at end ",
[lists:flatten(H)]),
exit(normal);
_ ->
ok
end
end, Hs).


check_headers([$\r, $\n |Tail], Last) when Tail /= [] ->
case lists:member(hd(Tail), [$\r, $\n]) of
true ->
error_logger:error_msg("Bad header ~p, it contains"
" '\\r' or '\\n' at end ", [lists:reverse(Last)]),
exit(normal);
_ ->
check_headers(Tail, [])
end;
-define(h_check(H, Field),
f_check(H#outh.Field, Field)).

f_check(undefined, _Field) ->
ok;
f_check(Str, Field) ->
case lists:reverse(lists:flatten(Str)) of
[$\n, $\r , H | _Tail] ->
case lists:member(H, [$\n, $\r]) of
true ->
error_logger:format("Bad <~p> header:~n"
" ~p~nToo many newlines",
[Field, Str]),
exit(normal);
false ->
ok
end;
Other ->
error_logger:format("Bad <~p> header:~n"
"~p~nNot ending with CRNL~n",
[Field, Str]),
exit(normal)
end.

check_headers(H) ->
?h_check(H, connection),
?h_check(H, server),
?h_check(H, location),
?h_check(H, cache_control),
?h_check(H, date),
?h_check(H, allow),
?h_check(H, last_modified),
?h_check(H, etag),
?h_check(H, content_range),
?h_check(H, content_length),
?h_check(H, content_encoding),
?h_check(H, set_cookie),
?h_check(H, transfer_encoding),
?h_check(H, www_authenticate),
check_other(H#outh.other).


check_other(undefined) ->
ok;
check_other(L0) ->
L = lists:flatten(L0),
case lists:dropwhile(fun(X) -> not lists:member(X, ["\r\n"]) end, L) of
[] ->
ok;
[$\r, $\n, H | _Tail] ->
case lists:member(H, [$\n, $\r]) of
true ->
bad_other(L);
false ->
ok
end;
_Other ->
bad_other(L)
end.


bad_other(L) ->
Bad = lists:takewhile(
fun(X) -> not lists:member(X, ["\r\n"]) end, L),
error_logger:format("Bad header:~p~n"
"Too many newlines",
[Bad]),
exit(normal).

check_headers([H|T], Last) ->
check_headers(T, [H|Last]);
check_headers([], _) ->
ok.



Expand Down
28 changes: 16 additions & 12 deletions src/yaws_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ l2a(A) when atom(A) -> A.
%% ignore |
%% {stop, Reason}
%%----------------------------------------------------------------------

init([]) ->
process_flag(trap_exit, true),
put(start_time, calendar:local_time()), %% for uptime
Expand Down Expand Up @@ -187,22 +188,25 @@ init([]) ->
end.


init2(Gconf, Sconfs, RunMod, FirstTime) ->
put(gc, Gconf),
init2(GC, Sconfs, RunMod, FirstTime) ->
put(gc, GC),
lists:foreach(
fun(D) ->
yaws_debug:format("Add path ~p~n", [D]),
code:add_pathz(D)
end, Gconf#gconf.ebin_dir),
yaws_debug:format("Running with id=~p~n", [Gconf#gconf.id]),
setup_dirs(Gconf),
yaws_ctl:start(Gconf, FirstTime),
runmod(RunMod, Gconf),
end, GC#gconf.ebin_dir),
yaws_debug:format("Running with id=~p~n"
"Running with debug checks turned on (slower server) ~n"
"Logging to directory ~p~n",
[GC#gconf.id, GC#gconf.logdir]),
setup_dirs(GC),
yaws_ctl:start(GC, FirstTime),
runmod(RunMod, GC),

%% start the individual gserv server processes
L = lists:map(
fun(Group) ->
proc_lib:start_link(?MODULE, gserv, [Gconf, Group])
proc_lib:start_link(?MODULE, gserv, [GC, Group])
end, Sconfs),
L2 = lists:zf(fun({error, F, A}) ->
error_logger:error_msg(F, A),
Expand All @@ -216,18 +220,18 @@ init2(Gconf, Sconfs, RunMod, FirstTime) ->
false
end, L),
?Debug("L=~p~n", [yaws_debug:nobin(L)]),
yaws_log:uid_change(Gconf),
yaws_log:uid_change(GC),


%% and now finally, we've opened the ctl socket and are
%% listening to all sockets we can possibly change uid

GC2 = case (catch yaws:setuser(Gconf#gconf.username)) of
GC2 = case (catch yaws:setuser(GC#gconf.username)) of
ignore ->
Gconf;
GC;
{ok, NewUid} ->
error_logger:info_msg("Changed uid to ~s~n", [NewUid]),
Gconf#gconf{uid = NewUid};
GC#gconf{uid = NewUid};
Other ->
error_logger:error_msg("Failed to set user:~n~p", [Other]),
exit(Other)
Expand Down
8 changes: 3 additions & 5 deletions www/code.yaws
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@

out(A) ->
Head = yaws_api:ssi(A#arg.docroot, ["/HEAD", "/EXHEAD"]),

L = yaws_api:parse_query(A),
{Code, F} = case lists:keysearch(file, 1, L) of
{value, {_, Fname}} ->
{Code, F} = case queryvar(A, "file") of
{ok, Fname} ->
case file:read_file(A#arg.docroot ++ undot(Fname)) of
{ok, B} ->
{yaws_api:pre_ssi_string(binary_to_list(B),"box"), Fname};
_ ->
{[], "Can't read " ++ Fname }
end;
false ->
undefined ->
{[], "Bad request"}
end,
Trail = yaws_api:ssi(A#arg.docroot, ["/END"]),
Expand Down
4 changes: 2 additions & 2 deletions www/dynamic.yaws
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ out(A) ->
{li,[],
[{p,[],
[{a, [{href, "index.yaws"}], "The top page, index.yaws"},
" and then the",
" and then the ",
{a, [{href, "code.yaws?file=/index.yaws"}], "corresponding source"}]}]},

{li,[],
[{p,[],
[{a, [{href, "dynamic.yaws"}], "This page, dynamic.yaws"},
" and then the",
" and then the ",
{a, [{href, "code.yaws?file=/dynamic.yaws"}], "corresponding source"}]}]}
]},

Expand Down
3 changes: 2 additions & 1 deletion www/form.yaws
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ How many tabs to you indent? <input NAME="tabs" TYPE=int>

Your email <input NAME="contact" SIZE="42">

<p>Many thanks on behalf of the Windows central support team.
<p>Submit this POST to get an explanation of how to process the
POSTed data.

<p><input TYPE=submit> <input TYPE=reset>

Expand Down
6 changes: 4 additions & 2 deletions www/post.yaws
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ out(A) ->
{hr},
{'div',[{class,"box"}],
{p,[], ["The favourite programming language is ",
postvar(A,"lang")]}}

case postvar(A,"lang") of
undefined -> "None";
{ok, Val} -> Val
end]}}
]},
{ssi, "END",[],[]}].

Expand Down

0 comments on commit ffee7fc

Please sign in to comment.