Permalink
Browse files

ensure compatibility with Erlang R13B04

For R13B04 compatibility, fix bare calls to integer_to_list and
list_to_integer, and in yaws_davlock provide an alternative for pre-R14 for
finding hwaddrs.
  • Loading branch information...
1 parent 0f41b7b commit 954ccb189900c6fdeaf3b5d33a102a61730b9f9d @vinoski vinoski committed Oct 23, 2012
Showing with 73 additions and 50 deletions.
  1. +26 −24 src/yaws.erl
  2. +1 −1 src/yaws_dav.erl
  3. +27 −4 src/yaws_davlock.erl
  4. +14 −16 test/t2/app_test.erl
  5. +5 −5 test/t4/app_test.erl
View
@@ -426,7 +426,7 @@ upto(I, [H|T]) -> [H|upto(I-1, T)].
to_string(X) when is_float(X) -> io_lib:format("~.2.0f",[X]);
-to_string(X) when is_integer(X) -> integer_to_list(X);
+to_string(X) when is_integer(X) -> erlang:integer_to_list(X);
to_string(X) when is_atom(X) -> atom_to_list(X);
to_string(X) -> lists:concat([X]).
@@ -486,11 +486,11 @@ local_time_as_gmt_string(LocalTime) ->
time_to_string({{Year, Month, Day}, {Hour, Min, Sec}}, Zone) ->
[day(Year, Month, Day), ", ",
- mk2(Day), " ", month(Month), " ", integer_to_list(Year), " ",
+ mk2(Day), " ", month(Month), " ", erlang:integer_to_list(Year), " ",
mk2(Hour), ":", mk2(Min), ":", mk2(Sec), " ", Zone].
-mk2(I) when I < 10 -> [$0 | integer_to_list(I)];
-mk2(I) -> integer_to_list(I).
+mk2(I) when I < 10 -> [$0 | erlang:integer_to_list(I)];
+mk2(I) -> erlang:integer_to_list(I).
day(Year, Month, Day) ->
int_to_wd(calendar:day_of_the_week(Year, Month, Day)).
@@ -536,18 +536,18 @@ stringdate_to_datetime([_D1, _D2, _D3, $\,, $ |Tail]) ->
stringdate_to_datetime1(Tail).
stringdate_to_datetime1([A, B, $\s |T]) ->
- stringdate_to_datetime2(T, list_to_integer([A,B]));
+ stringdate_to_datetime2(T, erlang:list_to_integer([A,B]));
stringdate_to_datetime1([A, $\s |T]) ->
- stringdate_to_datetime2(T, list_to_integer([A])).
+ stringdate_to_datetime2(T, erlang:list_to_integer([A])).
stringdate_to_datetime2([M1, M2, M3, $\s , Y1, Y2, Y3, Y4, $\s,
H1, H2, $:, Min1, Min2,$:,
S1, S2,$\s ,$G, $M, $T|_], Day) ->
- {{list_to_integer([Y1,Y2,Y3,Y4]),
+ {{erlang:list_to_integer([Y1,Y2,Y3,Y4]),
month_str_to_int([M1, M2, M3]), Day},
- {list_to_integer([H1, H2]),
- list_to_integer([Min1, Min2]),
- list_to_integer([S1, S2])}}.
+ {erlang:list_to_integer([H1, H2]),
+ erlang:list_to_integer([Min1, Min2]),
+ erlang:list_to_integer([S1, S2])}}.
%% used by If-Modified-Since header code
@@ -1263,7 +1263,7 @@ make_cache_control_header(MimeType, FI) ->
make_cache_control_header(TTL) ->
- ["Cache-Control: ", "max-age=", integer_to_list(TTL), "\r\n"].
+ ["Cache-Control: ", "max-age=", erlang:integer_to_list(TTL), "\r\n"].
make_location_header(Where) ->
@@ -1301,14 +1301,14 @@ make_content_range_header(all) ->
undefined;
make_content_range_header({fromto, From, To, Tot}) ->
["Content-Range: bytes ",
- integer_to_list(From), $-, integer_to_list(To),
- $/, integer_to_list(Tot), $\r, $\n].
+ erlang:integer_to_list(From), $-, erlang:integer_to_list(To),
+ $/, erlang:integer_to_list(Tot), $\r, $\n].
make_content_length_header(Size) when is_integer(Size) ->
- ["Content-Length: ", integer_to_list(Size), "\r\n"];
+ ["Content-Length: ", erlang:integer_to_list(Size), "\r\n"];
make_content_length_header(FI) when is_record(FI, file_info) ->
Size = FI#file_info.size,
- ["Content-Length: ", integer_to_list(Size), "\r\n"];
+ ["Content-Length: ", erlang:integer_to_list(Size), "\r\n"];
make_content_length_header(_) ->
undefined.
@@ -1393,7 +1393,7 @@ outh_serialize() ->
undefined -> 200;
Int -> Int
end,
- StatusLine = ["HTTP/1.1 ", integer_to_list(Code), " ",
+ StatusLine = ["HTTP/1.1 ", erlang: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);
@@ -1534,7 +1534,7 @@ accumulate_header({"Content-Length", Len}) ->
I when is_integer(I) ->
accumulate_header({content_length, I});
L when is_list(L) ->
- accumulate_header({content_length, list_to_integer(L)})
+ accumulate_header({content_length, erlang:list_to_integer(L)})
end;
accumulate_header({transfer_encoding, What}) ->
@@ -1641,7 +1641,8 @@ user_to_home(User) ->
uid_to_name(Uid) ->
load_setuid_drv(),
- P = open_port({spawn, "setuid_drv " ++ [$n|integer_to_list(Uid)]}, []),
+ P = open_port({spawn, "setuid_drv " ++
+ [$n|erlang:integer_to_list(Uid)]}, []),
receive
{P, {data, "ok " ++ Name}} ->
Name
@@ -2081,9 +2082,9 @@ redirect_port(SC) ->
{"https", _, 443} -> "";
{"http", _, 80} -> "";
{_, undefined, 80} -> "";
- {_, undefined, Port} -> [$:|integer_to_list(Port)];
+ {_, undefined, Port} -> [$:|erlang:integer_to_list(Port)];
{_, _SSL, 443} -> "";
- {_, _SSL, Port} -> [$:|integer_to_list(Port)]
+ {_, _SSL, Port} -> [$:|erlang:integer_to_list(Port)]
end.
redirect_scheme_port(SC) ->
@@ -2132,8 +2133,9 @@ mktemp(Template, Ret) ->
mktemp(Dir, Template, Ret, I, Max, Suffix) when I < Max ->
{X,Y,Z} = now(),
- PostFix = integer_to_list(X) ++ "-" ++ integer_to_list(Y) ++ "-" ++
- integer_to_list(Z),
+ PostFix = erlang:integer_to_list(X) ++ "-" ++
+ erlang:integer_to_list(Y) ++ "-" ++
+ erlang:integer_to_list(Z),
F = filename:join(Dir, Template ++ [$_ | PostFix] ++ Suffix),
filelib:ensure_dir(F),
case file:open(F, [read, raw]) of
@@ -2201,7 +2203,7 @@ get_chunk_header(Fd, SSL) ->
end,
?Debug("Get chunk num from line ~p~n",[Line]),
{N, Exts} = split_at(Line, $;),
- {list_to_integer(strip_spaces(N),16), strip_spaces(Exts)};
+ {erlang:list_to_integer(strip_spaces(N),16), strip_spaces(Exts)};
{error, _Rsn} ->
exit(normal)
end.
@@ -2307,7 +2309,7 @@ integer_to_ip(_, _) ->
throw({error, einval}).
netmask_to_integer(Type, NetMask) ->
- case catch list_to_integer(NetMask) of
+ case catch erlang:list_to_integer(NetMask) of
I when is_integer(I) ->
case Type of
ipv4 -> (1 bsl ?MAXBITS_IPV4) - (1 bsl (?MAXBITS_IPV4 - I));
View
@@ -716,7 +716,7 @@ h_timeout(A) ->
I when is_integer(I) -> I;
_ -> ?LOCK_LIFETIME
end,
- min(Val,?LOCK_LIFETIME);
+ erlang:min(Val,?LOCK_LIFETIME);
_ -> ?LOCK_LIFETIME
end;
_ ->
View
@@ -338,10 +338,7 @@ locktoken() ->
<<TimeHi:12, TimeMid:16, TimeLow:32>> = <<Timestamp:60>>,
Clocksequence = <<Micro:14>>,
<<ClockseqHi:6, ClockseqLow:8>> = Clocksequence,
- {ok,Ifs} = inet:getifaddrs(),
- Addrs = [ lists:keysearch(hwaddr,1,Attr) || {_If,Attr} <- Ifs ],
- Addr = lists:max([ A || {value,{hwaddr,A}} <- Addrs ]),
- Node = list_to_binary(Addr),
+ Node = get_hwaddr(),
UUID = <<TimeLow:32, TimeMid:16, Version:4, TimeHi:12,
Variant:2, ClockseqLow:8, ClockseqHi:6, Node/binary>>,
<<U0:32, U1:16, U2:16, U3:16, U4:48>> = UUID,
@@ -353,3 +350,29 @@ format(["/"|T]) ->
format(T);
format([H|T]) ->
lists:flatten(["/",H|format(T)]).
+
+get_hwaddr() ->
+ get_hwaddr(erlang:function_exported(inet, getifaddrs, 0)).
+get_hwaddr(true) ->
+ {ok,Ifs} = inet:getifaddrs(),
+ Addrs = [ lists:keysearch(hwaddr,1,Attr) || {_If,Attr} <- Ifs ],
+ Addr = lists:max([ A || {value,{hwaddr,A}} <- Addrs ]),
+ list_to_binary(Addr);
+get_hwaddr(false) ->
+ %% this clause is for backward compatibility to R13
+ {ok, Ifs} = inet:getiflist(),
+ Addrs = lists:foldl(fun([{hwaddr, HW}], Acc) -> [HW|Acc];
+ ([], Acc) -> Acc
+ end, [], [begin {ok, HW} = inet:ifget(If, [hwaddr]), HW end || If <- Ifs]),
+ HWAddrs = case Addrs of
+ [] ->
+ %% hwaddr doesn't work on Mac on R13. Fall back to ifconfig :(
+ Ifconfig = os:cmd("/sbin/ifconfig -a"),
+ {ok, Pat} = re:compile("ether\s+([0-9a-fA-F:]+)"),
+ {match, Matches} = re:run(Ifconfig, Pat, [global, {capture, [1]}]),
+ HWs = [string:substr(Ifconfig, At+1, Len) || [{At,Len}] <- Matches],
+ [[erlang:list_to_integer(V, 16) || V <- string:tokens(S, ":")] || S <- HWs];
+ _ ->
+ Addrs
+ end,
+ list_to_binary(lists:max(HWAddrs)).
View
@@ -109,9 +109,7 @@ read_loop(C, I, Sz) ->
get_cont_len(C) ->
?line {value, {http_header, _,_,_, LenStr}} =
lists:keysearch('Content-Length', 3, tftest:get_headers(C)),
- {ok, list_to_integer(LenStr)}.
-
-
+ {ok, erlang:list_to_integer(LenStr)}.
test2() ->
@@ -532,7 +530,7 @@ recv_hdrs(Sock, Len) ->
{http, Sock, {http_error, Error}} ->
{error, Error};
{http, Sock, {http_header, _, 'Content-Length', _, LenStr}} ->
- recv_hdrs(Sock, list_to_integer(LenStr));
+ recv_hdrs(Sock, erlang:list_to_integer(LenStr));
{http, Sock, {http_header, _, _, _, _}} ->
recv_hdrs(Sock, Len);
{http, Sock, {http_response, _, 200, "OK"}} ->
@@ -555,7 +553,7 @@ small_post() ->
io:format(" small post\n",[]),
{ok, Bin} = file:read_file("../../www/1000.txt"),
Sz = size(Bin),
- Uri = "http://localhost:8006/posttest/" ++ integer_to_list(Sz),
+ Uri = "http://localhost:8006/posttest/" ++ erlang:integer_to_list(Sz),
Hdrs = [{content_length, Sz}, {content_type, "binary/octet-stream"}],
?line {ok, "200", _, _} = ibrowse:send_req(Uri, Hdrs, post, Bin, []),
ok.
@@ -564,7 +562,7 @@ large_post() ->
io:format(" large post\n",[]),
{ok, Bin} = file:read_file("../../www/10000.txt"),
Sz = size(Bin),
- Uri = "http://localhost:8006/posttest/" ++ integer_to_list(Sz),
+ Uri = "http://localhost:8006/posttest/" ++ erlang:integer_to_list(Sz),
Hdrs = [{content_length, Sz}, {content_type, "binary/octet-stream"}],
?line {ok, "200", _, _} = ibrowse:send_req(Uri, Hdrs, post, Bin, []),
ok.
@@ -573,7 +571,7 @@ small_chunked_post() ->
io:format(" small chunked post\n",[]),
{ok, Bin} = file:read_file("../../www/3000.txt"),
Sz = size(Bin),
- Uri = "http://localhost:8006/posttest/chunked/" ++ integer_to_list(Sz),
+ Uri = "http://localhost:8006/posttest/chunked/" ++ erlang:integer_to_list(Sz),
Hdrs = [{content_type, "binary/octet-stream"}],
Opts = [{transfer_encoding, {chunked, 1000*1000}}],
?line {ok, "200", _, _} = ibrowse:send_req(Uri, Hdrs, post, Bin, Opts),
@@ -583,7 +581,7 @@ large_chunked_post() ->
io:format(" large chunked post\n",[]),
{ok, Bin} = file:read_file("../../www/10000.txt"),
Sz = size(Bin),
- Uri = "http://localhost:8006/posttest/chunked/" ++ integer_to_list(Sz),
+ Uri = "http://localhost:8006/posttest/chunked/" ++ erlang:integer_to_list(Sz),
Hdrs = [{content_type, "binary/octet-stream"}],
%% size of chunk _IS_NOT_ a multiple of partial_post_size
@@ -609,7 +607,7 @@ flush_small_post() ->
io:format(" flush small post\n",[]),
{ok, Bin} = file:read_file("../../www/1000.txt"),
Sz = size(Bin),
- Uri1 = "http://localhost:8006/flushtest/" ++ integer_to_list(Sz),
+ Uri1 = "http://localhost:8006/flushtest/" ++ erlang:integer_to_list(Sz),
Uri2 = "http://localhost:8006/hello.txt",
Hdrs = [{content_length, Sz}, {content_type, "binary/octet-stream"}],
{ok, ConnPid} = ibrowse:spawn_worker_process("localhost", 8006),
@@ -622,7 +620,7 @@ flush_large_post() ->
io:format(" flush large post\n",[]),
{ok, Bin} = file:read_file("../../www/10000.txt"),
Sz = size(Bin),
- Uri1 = "http://localhost:8006/flushtest/" ++ integer_to_list(Sz),
+ Uri1 = "http://localhost:8006/flushtest/" ++ erlang:integer_to_list(Sz),
Uri2 = "http://localhost:8006/hello.txt",
Hdrs = [{content_length, Sz}, {content_type, "binary/octet-stream"}],
{ok, ConnPid} = ibrowse:spawn_worker_process("localhost", 8006),
@@ -635,7 +633,7 @@ flush_chunked_post() ->
io:format(" flush chunked post\n",[]),
{ok, Bin} = file:read_file("../../www/10000.txt"),
Sz = size(Bin),
- Uri1 = "http://localhost:8006/flushtest/chunked/" ++ integer_to_list(Sz),
+ Uri1 = "http://localhost:8006/flushtest/chunked/" ++ erlang:integer_to_list(Sz),
Uri2 = "http://localhost:8006/hello.txt",
Hdrs = [{content_type, "binary/octet-stream"}],
Opts = [{transfer_encoding, {chunked, 4000*1000}}],
@@ -687,20 +685,20 @@ test_te_trailer_and_extensions() ->
Data = ["This is the data in the first chunk\n",
"and this is the second one\n",
"con", "sequence"],
- Path = "/posttest/chunked/" ++ integer_to_list(length(lists:flatten(Data))),
+ Path = "/posttest/chunked/" ++ erlang:integer_to_list(length(lists:flatten(Data))),
?line gen_tcp:send(Sock, "POST "++Path++" HTTP/1.1\r\n"
"Host: localhost\r\n"
"Trailer: Content-Type\r\n"
"Trailer: Extra-Headers-WooHoo\r\n"
"Transfer-Encoding: Chunked\r\n\r\n"),
- Body = lists:flatten([[integer_to_list(length(X), 16),"; foo=bar\r\n",
+ Body = lists:flatten([[erlang:integer_to_list(length(X), 16),"; foo=bar\r\n",
X,"\r\n"] || X <- Data]),
?line gen_tcp:send(Sock, Body),
?line gen_tcp:send(Sock, "0\r\n"
"Extra-Headers-WooHoo: something\r\n"
"Content-Type: text/plain\r\n\r\n"),
inet:setopts(Sock, [{packet, http}]),
- ?line {ok, Len} = recv_hdrs(Sock),
+ ?line {ok, _Len} = recv_hdrs(Sock),
gen_tcp:close(Sock),
ok.
@@ -712,7 +710,7 @@ test_expires() ->
%% Retrieve max-age value to test Expires header
?line "max-age=" ++ Rest = proplists:get_value("Cache-Control", Hdrs),
- ?line Secs = list_to_integer(Rest),
+ ?line Secs = erlang:list_to_integer(Rest),
%% Convert Date and Expires into datetime()
?line Date = proplists:get_value("Date", Hdrs),
@@ -837,7 +835,7 @@ test_ssl_multipart_post() ->
],
Uri = "https://localhost:8444/test_upload_ssl.yaws",
Options = [{is_ssl, true}, {ssl_options, [{verify, 0}]}],
- ?line {ok, "200", _, _} = Reply = ibrowse:send_req(Uri, Headers, post, Data, Options),
+ ?line {ok, "200", _, _} = ibrowse:send_req(Uri, Headers, post, Data, Options),
ok = application:stop(ssl),
ok = application:stop(public_key),
ok = application:stop(crypto),
View
@@ -92,7 +92,7 @@ test_post_revproxy() ->
small_post() ->
io:format(" small post\n",[]),
{ok, Bin} = file:read_file("../../www/1000.txt"),
- Sz = integer_to_list(size(Bin)),
+ Sz = erlang:integer_to_list(size(Bin)),
Uri = "http://localhost:8000/revproxy1/posttest/" ++ Sz,
Hdrs = [{content_length, Sz}, {content_type, "binary/octet-stream"}],
?line {ok, "200", _, _} = ibrowse:send_req(Uri, Hdrs, post, Bin, []),
@@ -101,7 +101,7 @@ small_post() ->
large_post() ->
io:format(" large post\n",[]),
{ok, Bin} = file:read_file("../../www/10000.txt"),
- Sz = integer_to_list(size(Bin)),
+ Sz = erlang:integer_to_list(size(Bin)),
Uri = "http://localhost:8000/revproxy1/posttest/" ++ Sz,
Hdrs = [{content_length, Sz}, {content_type, "binary/octet-stream"}],
?line {ok, "200", _, _} = ibrowse:send_req(Uri, Hdrs, post, Bin, []),
@@ -111,7 +111,7 @@ small_chunked_post() ->
%% Chunk size is less than partial_post_size
io:format(" small chunked post\n",[]),
{ok, Bin} = file:read_file("../../www/3000.txt"),
- Sz = integer_to_list(size(Bin)),
+ Sz = erlang:integer_to_list(size(Bin)),
Uri = "http://localhost:8000/revproxy1/posttest/chunked/" ++ Sz,
Hdrs = [{content_type, "binary/octet-stream"}],
Opts = [{transfer_encoding, {chunked, 1000*1000}}],
@@ -122,7 +122,7 @@ large_chunked_post() ->
%% Chunk size is greater than partial_post_size
io:format(" large chunked post\n",[]),
{ok, Bin} = file:read_file("../../www/10000.txt"),
- Sz = integer_to_list(size(Bin)),
+ Sz = erlang:integer_to_list(size(Bin)),
Uri = "http://localhost:8000/revproxy1/posttest/chunked/" ++ Sz,
Hdrs = [{content_type, "binary/octet-stream"}],
Opts = [{transfer_encoding, {chunked, 4000*1000}}],
@@ -268,7 +268,7 @@ recv_hdrs(Sock, Len) ->
{http, Sock, {http_error, Error}} ->
{error, Error};
{http, Sock, {http_header, _, 'Content-Length', _, LenStr}} ->
- recv_hdrs(Sock, list_to_integer(LenStr));
+ recv_hdrs(Sock, erlang:list_to_integer(LenStr));
{http, Sock, {http_header, _, _, _, _}} ->
recv_hdrs(Sock, Len);
{http, Sock, {http_response, _, 200, "OK"}} ->

0 comments on commit 954ccb1

Please sign in to comment.