Skip to content

Commit

Permalink
ssh: code reformatted
Browse files Browse the repository at this point in the history
  • Loading branch information
u3s committed Oct 21, 2024
1 parent 0515446 commit a264e68
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 25 deletions.
16 changes: 2 additions & 14 deletions lib/ssh/src/ssh.erl
Original file line number Diff line number Diff line change
Expand Up @@ -553,13 +553,10 @@ daemon(Socket, UserOptions) ->
{error,SockError} ->
{error,SockError}
end;

{error,OptionError} ->
{error,OptionError}
end.



-doc """
daemon(HostAddress, Port, Options) -> Result
Expand Down Expand Up @@ -590,8 +587,7 @@ The rules for handling the two address passing options are:
is set to the value of the 'ip'-option
""".
-spec daemon(any | inet:ip_address(), inet:port_number(), daemon_options()) -> {ok,daemon_ref()} | {error,term()}
;(socket, open_socket(), daemon_options()) -> {ok,daemon_ref()} | {error,term()}
.
;(socket, open_socket(), daemon_options()) -> {ok,daemon_ref()} | {error,term()}.

daemon(Host0, Port0, UserOptions0)
when 0 =< Port0, Port0 =< 65535, Host0 == any ;
Expand Down Expand Up @@ -644,7 +640,6 @@ daemon(Host0, Port0, UserOptions0)
OptionError = {error,_} ->
OptionError
end;

daemon(_, _, _) ->
{error, badarg}.

Expand Down Expand Up @@ -1227,21 +1222,18 @@ fp_fmt(b64, Bin) ->
%%--------------------------------------------------------------------
%% The handle_daemon_args/2 function basically only sets the ip-option in Opts
%% so that it is correctly set when opening the listening socket.

handle_daemon_args(any, Opts) ->
case proplists:get_value(ip, Opts) of
undefined -> {any, Opts};
IP -> {IP, Opts}
end;

handle_daemon_args(IPaddr, Opts) when is_tuple(IPaddr) ; IPaddr == loopback ->
case proplists:get_value(ip, Opts) of
undefined -> {IPaddr, [{ip,IPaddr}|Opts]};
IPaddr -> {IPaddr, Opts};
IP -> {IPaddr, [{ip,IPaddr}|Opts--[{ip,IP}]]} %% Backward compatibility
end.

%%%----------------------------------------------------------------
valid_socket_to_use(Socket, {tcp,_,_}) ->
%% Is this tcp-socket a valid socket?
try {is_tcp_socket(Socket),
Expand Down Expand Up @@ -1276,15 +1268,13 @@ close_listen_socket(ListenSocket, Options) ->
transport_connect(Host, Port, SocketOpts, Options) ->
{_, Callback, _} = ?GET_OPT(transport, Options),
Callback:connect(Host, Port, SocketOpts, ?GET_OPT(connect_timeout,Options)).

%%%----------------------------------------------------------------

-doc false.
is_host(X, Opts) ->
try is_host1(mangle_connect_address(X, Opts))
catch
_:_ -> false
end.


is_host1(L) when is_list(L) -> true; %% "string()"
is_host1(T) when tuple_size(T)==4 -> lists:all(fun(I) -> 0=<I andalso I=<255 end,
Expand All @@ -1293,7 +1283,6 @@ is_host1(T) when tuple_size(T)==16 -> lists:all(fun(I) -> 0=<I andalso I=<65535
tuple_to_list(T));
is_host1(loopback) -> true.

%%%----------------------------------------------------------------
mangle_connect_address(A, #{socket_options := SockOpts}) ->
mangle_connect_address(A, SockOpts);
mangle_connect_address(A, SockOpts) ->
Expand All @@ -1314,7 +1303,6 @@ mangle_connect_address1(A, _) ->
_ -> A
end.

%%%----------------------------------------------------------------
mangle_tunnel_address(any) -> <<"">>;
mangle_tunnel_address(loopback) -> <<"localhost">>;
mangle_tunnel_address({0,0,0,0}) -> <<"">>;
Expand Down
2 changes: 1 addition & 1 deletion lib/ssh/src/ssh_acceptor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
-export([start_link/3,
number_of_connections/1]).

%% spawn export
%% spawn export
-export([acceptor_init/4, acceptor_loop/6]).

-behaviour(ssh_dbg).
Expand Down
2 changes: 1 addition & 1 deletion lib/ssh/src/ssh_acceptor_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

%%
%%----------------------------------------------------------------------
%% Purpose: The acceptor supervisor for ssh servers hangs under
%% Purpose: The acceptor supervisor for ssh servers hangs under
%% ssh_system_sup.
%%----------------------------------------------------------------------

Expand Down
7 changes: 1 addition & 6 deletions lib/ssh/test/ssh_basic_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,9 @@ groups() ->
known_hosts,
ssh_file_is_host_key,
ssh_file_is_host_key_misc,
ssh_file_is_auth_key
]},

ssh_file_is_auth_key]},
{key_cb, [?PARALLEL], [key_callback, key_callback_options]},

{internal_error, [?PARALLEL], [internal_error]},

{login_bad_pwd_no_retry, [?PARALLEL], [login_bad_pwd_no_retry1,
login_bad_pwd_no_retry2,
login_bad_pwd_no_retry3,
Expand Down Expand Up @@ -1520,7 +1516,6 @@ check_error(Error) -> ct:fail(Error).
basic_test(Config) ->
ClientOpts = proplists:get_value(client_opts, Config),
ServerOpts = proplists:get_value(server_opts, Config),

{Pid, Host, Port} = ssh_test_lib:daemon(ServerOpts),
CM = ssh_test_lib:connect(Host, Port, ClientOpts),
ok = ssh:close(CM),
Expand Down
3 changes: 0 additions & 3 deletions lib/ssh/test/ssh_protocol_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1002,9 +1002,7 @@ client_close_after_hello(Config0) ->
]},
{send, hello}
]) || _ <- lists:seq(1,MaxSessions+100)],

ct:log("=== Tried to start ~p sessions.", [length(Cs)]),

ssh_info:print(fun ct:log/2),
{Parents, Conns, Handshakers} =
ssh_test_lib:find_handshake_parent(ssh_test_lib:server_port(Config)),
Expand Down Expand Up @@ -1161,7 +1159,6 @@ check_std_daemon_works(Config, Line) ->
server_user_password(Config) -> server_user_password(1, Config).

server_user_password(N, Config) -> lists:nth(N, ?v(user_passwords,Config)).


std_connect(Config) ->
std_connect({ssh_test_lib:server_host(Config),
Expand Down

0 comments on commit a264e68

Please sign in to comment.