aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorHans Nilsson <[email protected]>2013-11-18 16:37:54 +0100
committerHans Nilsson <[email protected]>2013-11-19 14:39:34 +0100
commit5a5c226e35ff3475b9ed0480809d019a135e2532 (patch)
tree4b6889732e4df0fa6243806d3cf37ae1f8c15515 /lib
parent787dfe7cdec35d43f5f88311b60b6288e39e7ffb (diff)
downloadotp-5a5c226e35ff3475b9ed0480809d019a135e2532.tar.gz
otp-5a5c226e35ff3475b9ed0480809d019a135e2532.tar.bz2
otp-5a5c226e35ff3475b9ed0480809d019a135e2532.zip
ftp: small fixes
Diffstat (limited to 'lib')
-rw-r--r--lib/inets/src/ftp/ftp.erl27
-rw-r--r--lib/inets/test/ftp_SUITE.erl56
2 files changed, 39 insertions, 44 deletions
diff --git a/lib/inets/src/ftp/ftp.erl b/lib/inets/src/ftp/ftp.erl
index bfb4b27b45..86ef9280ad 100644
--- a/lib/inets/src/ftp/ftp.erl
+++ b/lib/inets/src/ftp/ftp.erl
@@ -39,7 +39,8 @@
send_chunk_start/2, send_chunk/2, send_chunk_end/1,
type/2, user/3, user/4, account/2,
append/3, append/2, append_bin/3,
- append_chunk/2, append_chunk_end/1, append_chunk_start/2, info/1]).
+ append_chunk/2, append_chunk_end/1, append_chunk_start/2,
+ info/1, latest_ctrl_response/1]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2,
@@ -84,6 +85,7 @@
%% and hence the end of the response is reached!
ctrl_data = {<<>>, [], start}, % {binary(), [bytes()], LineStatus}
%% pid() - Client pid (note not the same as "From")
+ latest_ctrl_response = "",
owner = undefined,
client = undefined, % "From" to be used in gen_server:reply/2
%% Function that activated a connection and maybe some
@@ -753,6 +755,18 @@ info(Pid) ->
call(Pid, info, list).
+%%--------------------------------------------------------------------------
+%% latest_ctrl_response(Pid) -> string()
+%% Pid = pid()
+%%
+%% Description: The latest received response from the server
+%%--------------------------------------------------------------------------
+
+-spec latest_ctrl_response(Pid :: pid()) -> string().
+
+latest_ctrl_response(Pid) ->
+ call(Pid, latest_ctrl_response, string).
+
%%%========================================================================
%%% Behavior callbacks
%%%========================================================================
@@ -1046,6 +1060,9 @@ handle_call({_, info}, _, #state{verbose = Verbose,
{progress, Progress}],
{reply, {ok, Options}, State};
+handle_call({_,latest_ctrl_response}, _, #state{latest_ctrl_response=Resp} = State) ->
+ {reply, {ok,Resp}, State};
+
%% But everything else must come from the owner
handle_call({Pid, _}, _, #state{owner = Owner} = State) when Owner =/= Pid ->
{reply, {error, not_connection_owner}, State};
@@ -1398,13 +1415,15 @@ handle_info({Transport, Socket, Data}, #state{csock = {Transport, Socket},
gen_server:reply(From, string:tokens(Lines, [?CR, ?LF])),
{noreply, State#state{client = undefined,
caller = undefined,
+ latest_ctrl_response = Lines,
ctrl_data = {NextMsgData, [],
start}}};
_ ->
?DBG(' ...handle_ctrl_result(~p,...) ctrl_data=~p~n',[CtrlResult,{NextMsgData, [], start}]),
handle_ctrl_result(CtrlResult,
- State#state{ctrl_data =
- {NextMsgData, [], start}})
+ State#state{latest_ctrl_response = Lines,
+ ctrl_data =
+ {NextMsgData, [], start}})
end;
{continue, NewCtrlData} ->
?DBG(' ...Continue... ctrl_data=~p~n',[NewCtrlData]),
@@ -2167,7 +2186,7 @@ send_ctrl_message(_S=#state{csock = Socket, verbose = Verbose}, Message) ->
send_message(Socket, Message).
send_data_message(_S=#state{dsock = Socket}, Message) ->
- ?DBG('<==data ~p ==== ~s~p~n',[Socket,Message,_S]),
+ ?DBG('<==data ~p ==== ~s~n~p~n',[Socket,Message,_S]),
case send_message(Socket, Message) of
ok ->
ok;
diff --git a/lib/inets/test/ftp_SUITE.erl b/lib/inets/test/ftp_SUITE.erl
index dea147fb56..28adcf822b 100644
--- a/lib/inets/test/ftp_SUITE.erl
+++ b/lib/inets/test/ftp_SUITE.erl
@@ -106,15 +106,16 @@ ftp_tests()->
%%% % if the server is running. [] if not running.
%%% % The string in string() is suitable for logging.
%%% StopCommand, % fun(start_result()) -> void(). The command to stop the daemon with.
-%%% Host, % string(). Mostly "localhost"
-%%% Port % pos_integer()
+%%% AugmentFun, % fun(config()) -> config() Adds two funs for transforming names of files
+%%% % and directories to the form they are returned from this server
+%%% ServerHost, % string(). Mostly "localhost"
+%%% ServerPort % pos_integer()
%%% }
%%%
-define(default_ftp_servers,
[{"vsftpd",
fun(__CONF__) ->
-%% make_config_file(vsftpd, Conf),
DataDir = ?config(data_dir,__CONF__),
ConfFile = filename:join(DataDir, "vsftpd.conf"),
AnonRoot = ?config(priv_dir,__CONF__),
@@ -208,7 +209,18 @@ init_per_testcase(Case, Config0) ->
end_per_testcase(user, _Config) -> ok;
end_per_testcase(bad_user, _Config) -> ok;
-end_per_testcase(_Case, Config) -> ftp__close(Config).
+end_per_testcase(_Case, Config) ->
+ case ?config(tc_status,Config) of
+ ok -> ok;
+ _ ->
+ try ftp:latest_ctrl_response(?config(ftp,Config))
+ of
+ {ok,S} -> ct:log("***~n*** Latest ctrl channel response:~n*** ~p~n***",[S])
+ catch
+ _:_ -> ok
+ end
+ end,
+ ftp__close(Config).
%%--------------------------------------------------------------------
%% Test Cases --------------------------------------------------------
@@ -235,7 +247,6 @@ pwd(Config0) ->
Pid = ?config(ftp, Config),
{ok, PWD} = ftp:pwd(Pid),
{ok, PathLpwd} = ftp:lpwd(Pid),
- ct:log("PWD=~p~nPathLpwd=~p",[PWD,PathLpwd]),
PWD = id2ftp_result("", Config),
PathLpwd = id2ftp_result("", Config).
@@ -249,7 +260,6 @@ cd(Config0) ->
ok = ftp:cd(Pid, id2ftp(Dir,Config)),
{ok, PWD} = ftp:pwd(Pid),
ExpectedPWD = id2ftp_result(Dir, Config),
- ct:log("PWD=~p~nExpectedPWD=~p",[PWD,ExpectedPWD]),
PWD = ExpectedPWD,
{error, epath} = ftp:cd(Pid, ?BAD_DIR).
@@ -263,7 +273,6 @@ lcd(Config0) ->
ok = ftp:lcd(Pid, id2ftp(Dir,Config)),
{ok, PWD} = ftp:lpwd(Pid),
ExpectedPWD = id2ftp_result(Dir, Config),
- ct:log("PWD=~p~nExpectedPWD=~p",[PWD,ExpectedPWD]),
PWD = ExpectedPWD,
{error, epath} = ftp:lcd(Pid, ?BAD_DIR).
@@ -497,7 +506,6 @@ recv_chunk(Config0) ->
{{error, "ftp:recv_chunk_start/2 not called"},_} = recv_chunk(Pid, <<>>),
ok = ftp:recv_chunk_start(Pid, id2ftp(File,Config)),
{ok, ReceivedContents, Nchunks} = recv_chunk(Pid, <<>>),
- ct:log("Received ~p chunks",[Nchunks]),
find_diff(ReceivedContents, Contents).
recv_chunk(Pid, Acc) -> recv_chunk(Pid, Acc, 0).
@@ -582,7 +590,6 @@ chk_file(Path=[C|_], ExpectedContents, Config) when 0<C,C=<255 ->
chk_file(PathList, ExpectedContents, Config) ->
Path = filename:join(PathList),
AbsPath = id2abs(Path,Config),
-ct:log("chk_file/3 dbg: PathList=~p, Path=~p~nAbsPath=~p",[PathList,Path,AbsPath]),
case file:read_file(AbsPath) of
{ok,ExpectedContents} ->
true;
@@ -675,7 +682,6 @@ start_ftpd(Config) ->
{Name,StartCmd,ChkUp,_StopCommand,ConfigRewrite,Host,Port} = ?config(ftpd_data, Config),
case StartCmd(Config) of
{ok,StartResult} ->
- ct:log( ChkUp(StartResult) ),
[{ftpd_host,Host},
{ftpd_port,Port},
{ftpd_start_result,StartResult} | ConfigRewrite(Config)];
@@ -730,33 +736,6 @@ find_diff(<<H,T1/binary>>, <<H,T2/binary>>, Pos) -> find_diff(T1, T2, Pos+1);
find_diff(RC, LC, Pos) -> {error, {diff, Pos, RC, LC}}.
%%--------------------------------------------------------------------
%%
-make_config_file(vsftpd, Config) ->
- ct:log("Config=~p",[Config]),
- DstFileName = filename:join(?config(data_dir,Config), "vsftpd.conf"),
- ct:log("DstFileName=~p",[DstFileName]),
- SrcFileName = DstFileName ++ ".src",
- ct:log("SrcFileName=~p",[SrcFileName]),
- Chroot = ?config(priv_dir,Config),
- ct:log("Chroot=~p",[Chroot]),
- {ok,SrcContents} = file:read_file(SrcFileName),
- ct:log("SrcContents=~p",[SrcContents]),
- SFN = list_to_binary(SrcFileName),
- CHR = list_to_binary(Chroot),
- DstContents =
- <<"## Generated, do not edit!\n",
- "## Source: ",SFN/binary,"\n",
- "\n",
- "chroot_local_user=YES\n",
- "passwd_chroot_enable=",CHR/binary,"\n",
- "\n",
- SrcContents/binary
- >>,
- ct:log("DstContents=~p",[DstContents]),
- file:write_file(DstFileName, DstContents).
-
-
-%%--------------------------------------------------------------------
-%%
set_state(Ops, Config) when is_list(Ops) -> lists:foldl(fun set_state/2, Config, Ops);
set_state(reset, Config) ->
@@ -779,7 +758,6 @@ set_state({mkfile,Id,Contents}, Config) ->
mk_path(Abs) -> lists:foldl(fun mk_path/2, [], filename:split(filename:dirname(Abs))).
mk_path(F, Pfx) ->
-io:format('~p~n',[filename:join(Pfx,F)]),
case file:read_file_info(AbsName=filename:join(Pfx,F)) of
{ok,#file_info{type=directory}} ->
AbsName;
@@ -793,10 +771,8 @@ io:format('~p~n',[filename:join(Pfx,F)]),
rm('*', Pfx) ->
{ok,Fs} = file:list_dir(Pfx),
- ct:log("Deleting ~p with prefix=~p",[Fs,Pfx]),
lists:foreach(fun(F) -> rm(F, Pfx) end, Fs);
rm(F, Pfx) ->
- ct:log("rm ~p in ~p",[F,Pfx]),
case file:read_file_info(AbsName=filename:join(Pfx,F)) of
{ok,#file_info{type=directory}} ->
{ok,Fs} = file:list_dir(AbsName),