From e7abd910a9cd94677bbcb19cdf5a2bdc2cb83279 Mon Sep 17 00:00:00 2001
From: Hans Nilsson The
If the Type definitions that are used more than once in this module,
- or abstractions to indicate the intended use of the data
- type, or both: list of ASCII characters opaque() -as returned by
- Data has arrived on the channel. This event is sent as a
- result of calling Indicates that the other side sends no more data.
- This event is sent as a result of calling The valid values are The result of a call. If the request reached the peer, was handled and the response
+ reached the requesting node the If not, the The status of a request.
+ Coresponds to the As mentioned in the introduction, the
+ Data has arrived on the channel. This event is sent as a result of calling
+ Indicates that the other side sends no more data. This event is sent as a result of calling
+ A signal can be delivered to the remote process/service
+ A signal can be delivered to the remote process/service
using the following message. Some systems do not support
signals, in which case they are to ignore this message. There is
currently no function to generate this event as the signals
referred to are on OS-level and not something generated by an
- Erlang program.
A remote execution can terminate violently because of a signal.
+ A remote execution can terminate violently because of a signal.
Then this message can be received. For details on valid string
values, see
When the command running at the other end terminates, the + Section 6.10, which shows a special case of these signals.
+ + +When the command running at the other end terminates, the
following message can be sent to return the exit status of the
command. A zero
This event is sent as a result of calling + ssh_connection:exit_status/3.
+ + +This event is sent as a result of calling
Channels implementing a shell and command execution on the server side are to handle the following messages that can be sent by client- channel processes.
@@ -146,22 +189,24 @@Events that include a
Environment variables can be passed to the shell/command
+ Environment variables can be passed to the shell/command
to be started later. This event is sent as a result of calling
A pseudo-terminal has been requested for the +
+ + + +A pseudo-terminal has been requested for the
session.
This message requests that the user default shell
+ This message requests that the user default shell
is started at the other end. This event is sent as a result of calling
When the window (terminal) size changes on the client
+ When the window (terminal) size changes on the client
side, it can send a message to the server side to inform it of
- the new dimensions. No API function generates this event.
This message requests that the server starts
+ This message requests that the server starts
execution of the given command. This event is sent as a result of calling
Adjusts the SSH flow control window. This is to be done by both the client- and server-side channel processes.
@@ -221,17 +272,12 @@A server- or client-channel process can choose to close their session by sending a close event.
-This function is called by the
Is to be called by a client-channel process to request that the server starts
executing the given command. The result is several messages according to the
following pattern. The last message is a channel close message, as the
The result of executing the command can be only one line + or thousands of lines depending on the command.
Indicates that no more data is to be sent.
Not all systems send signals. For details on valid string + values, see RFC 4254, Section 6.10
It is recommended by the SSH Connection Protocol to send this + message, but that is not always the case.
Indicates that the
Is to be called by a server-channel process to send the exit status of a command to the client.
@@ -298,16 +348,10 @@Sends an SSH Connection Protocol
Sends status replies to requests where the requester has
stated that it wants a status report, that is, Is to be called by client- and server-channel processes to send data to each other.
@@ -380,29 +419,17 @@
Sends EOF on channel
Opens a channel for an SSH session. The channel id returned from this function is the id used as input to the other functions in this module.
@@ -410,17 +437,9 @@Environment variables can be passed before starting the shell/command. Is to be called by a client channel processes.
@@ -428,14 +447,9 @@Is to be called by a client channel process to request that the user default shell (typically defined in /etc/passwd in Unix systems) is executed @@ -448,15 +462,8 @@
Is to be called by a client-channel process for requesting to execute a predefined
subsystem on the server.
diff --git a/lib/ssh/src/ssh_connection.erl b/lib/ssh/src/ssh_connection.erl
index 83f85b1d8e..1e54be2a16 100644
--- a/lib/ssh/src/ssh_connection.erl
+++ b/lib/ssh/src/ssh_connection.erl
@@ -67,6 +67,79 @@
-type connection_ref() :: ssh:connection_ref().
-type channel_id() :: ssh:channel_id().
+-type req_status() :: success | failure .
+-type reason() :: closed | timeout .
+
+-type result() :: req_status() | {error, reason()} .
+
+-type ssh_data_type_code() :: non_neg_integer(). % Only 0 and 1 are used
+
+
+%%% The SSH Connection Protocol
+
+-export_type([event/0,
+ ssh_event_msg/0,
+ data_event/0,
+ data_data_event/0,
+ data_eof_event/0,
+ status_event/0,
+ status_signal_event/0,
+ status_exit_signal_event/0,
+ status_exit_status_event/0,
+ status_closed_event/0,
+ terminal_event/0,
+ terminal_env_event/0,
+ terminal_pty_event/0,
+ terminal_shell_event/0,
+ terminal_window_change_event/0,
+ terminal_exec_event/0
+ ]).
+
+-type event() :: {ssh_cm, ssh:connection_ref(), ssh_event_msg()}.
+-type ssh_event_msg() :: data_event() | status_event() | terminal_event() .
+
+-type data_event() :: data_data_event()
+ | data_eof_event() .
+-type data_data_event() :: {data, ssh:channel_id(), ssh_data_type_code(), Data :: binary()} .
+-type data_eof_event() :: {eof, ssh:channel_id()} .
+
+
+-type status_event() :: status_signal_event()
+ | status_exit_signal_event()
+ | status_exit_status_event()
+ | status_closed_event() .
+
+-type status_signal_event() :: {signal, ssh:channel_id(), SignalName::string()} .
+-type status_exit_signal_event() :: {exit_signal, ssh:channel_id(),
+ ExitSignal :: string(),
+ ErrorMsg ::string(),
+ LanguageString :: string()} .
+-type status_exit_status_event() :: {exit_status, ssh:channel_id(), ExitStatus :: integer()} .
+-type status_closed_event() :: {closed, ssh:channel_id()} .
+
+-type terminal_event() :: terminal_env_event()
+ | terminal_pty_event()
+ | terminal_shell_event()
+ | terminal_window_change_event()
+ | terminal_exec_event() .
+
+-type terminal_env_event() :: {env, ssh:channel_id(), WantReply :: boolean(), Var ::string(), Value :: string()} .
+-type terminal_pty_event() :: {pty, ssh:channel_id(),
+ WantReply :: boolean(),
+ {Terminal :: string(), CharWidth :: integer(), RowHeight :: integer(), PixelWidth :: integer(), PixelHeight :: integer(),
+ TerminalModes :: [{Opcode :: atom() | integer(),
+ Value :: integer()}]}} .
+-type terminal_shell_event() :: {shell, WantReply :: boolean()} .
+-type terminal_window_change_event() :: {window_change, ssh:channel_id(), CharWidth :: integer(),
+ RowHeight :: integer(), PixWidth :: integer(), PixHeight :: integer()} .
+-type terminal_exec_event() :: {exec, ssh:channel_id(), WantReply :: boolean(), Cmd :: string()} .
+
+%%% This function is soley to convince all
+%%% checks that the type event() exists...
+-export([dummy/1]).
+-spec dummy(event()) -> false.
+dummy(_) -> false.
+
%%--------------------------------------------------------------------
%%% API
%%--------------------------------------------------------------------
@@ -77,14 +150,21 @@
%% application, a system command, or some built-in subsystem.
%% --------------------------------------------------------------------
--spec session_channel(connection_ref(), timeout()) ->
- {ok, channel_id()} | {error, timeout | closed}.
+-spec session_channel(ConnectionRef, Timeout) -> Result when
+ ConnectionRef :: ssh:connection_ref(),
+ Timeout :: timeout(),
+ Result :: {ok, ssh:channel_id()} | {error, reason()} .
session_channel(ConnectionHandler, Timeout) ->
session_channel(ConnectionHandler, ?DEFAULT_WINDOW_SIZE, ?DEFAULT_PACKET_SIZE, Timeout).
--spec session_channel(connection_ref(), integer(), integer(), timeout()) ->
- {ok, channel_id()} | {error, timeout | closed}.
+
+-spec session_channel(ConnectionRef, InitialWindowSize, MaxPacketSize, Timeout) -> Result when
+ ConnectionRef :: ssh:connection_ref(),
+ InitialWindowSize :: pos_integer(),
+ MaxPacketSize :: pos_integer(),
+ Timeout :: timeout(),
+ Result :: {ok, ssh:channel_id()} | {error, reason()} .
session_channel(ConnectionHandler, InitialWindowSize, MaxPacketSize, Timeout) ->
case ssh_connection_handler:open_channel(ConnectionHandler, "session", <<>>,
@@ -100,8 +180,11 @@ session_channel(ConnectionHandler, InitialWindowSize, MaxPacketSize, Timeout) ->
%% Description: Will request that the server start the
%% execution of the given command.
%%--------------------------------------------------------------------
--spec exec(connection_ref(), channel_id(), string(), timeout()) ->
- success | failure | {error, timeout | closed}.
+-spec exec(ConnectionRef, ChannelId, Command, Timeout) -> result() when
+ ConnectionRef :: ssh:connection_ref(),
+ ChannelId :: ssh:channel_id(),
+ Command :: string(),
+ Timeout :: timeout().
exec(ConnectionHandler, ChannelId, Command, TimeOut) ->
ssh_connection_handler:request(ConnectionHandler, self(), ChannelId, "exec",
@@ -112,8 +195,10 @@ exec(ConnectionHandler, ChannelId, Command, TimeOut) ->
%% defined in /etc/passwd in UNIX systems) be started at the other
%% end.
%%--------------------------------------------------------------------
--spec shell(connection_ref(), channel_id()) ->
- ok | success | failure | {error, timeout}.
+-spec shell(ConnectionRef, ChannelId) -> Result when
+ ConnectionRef :: ssh:connection_ref(),
+ ChannelId :: ssh:channel_id(),
+ Result :: ok | success | failure | {error, timeout} .
shell(ConnectionHandler, ChannelId) ->
ssh_connection_handler:request(ConnectionHandler, self(), ChannelId,
@@ -122,8 +207,11 @@ shell(ConnectionHandler, ChannelId) ->
%%
%% Description: Executes a predefined subsystem.
%%--------------------------------------------------------------------
--spec subsystem(connection_ref(), channel_id(), string(), timeout()) ->
- success | failure | {error, timeout | closed}.
+-spec subsystem(ConnectionRef, ChannelId, Subsystem, Timeout) -> result() when
+ ConnectionRef :: ssh:connection_ref(),
+ ChannelId :: ssh:channel_id(),
+ Subsystem :: string(),
+ Timeout :: timeout().
subsystem(ConnectionHandler, ChannelId, SubSystem, TimeOut) ->
ssh_connection_handler:request(ConnectionHandler, self(),
@@ -134,12 +222,13 @@ subsystem(ConnectionHandler, ChannelId, SubSystem, TimeOut) ->
%%--------------------------------------------------------------------
-spec send(connection_ref(), channel_id(), iodata()) ->
ok | {error, timeout | closed}.
+
send(ConnectionHandler, ChannelId, Data) ->
send(ConnectionHandler, ChannelId, 0, Data, infinity).
--spec send(connection_ref(), channel_id(), integer()| iodata(), timeout() | iodata()) ->
- ok | {error, timeout | closed}.
+-spec send(connection_ref(), channel_id(), iodata(), timeout()) -> ok | {error, reason()};
+ (connection_ref(), channel_id(), ssh_data_type_code(), iodata()) -> ok | {error, reason()}.
send(ConnectionHandler, ChannelId, Data, TimeOut) when is_integer(TimeOut) ->
send(ConnectionHandler, ChannelId, 0, Data, TimeOut);
@@ -151,14 +240,15 @@ send(ConnectionHandler, ChannelId, Type, Data) ->
send(ConnectionHandler, ChannelId, Type, Data, infinity).
--spec send(connection_ref(), channel_id(), integer(), iodata(), timeout()) ->
- ok | {error, timeout | closed}.
+-spec send(connection_ref(), channel_id(), ssh_data_type_code(), iodata(), timeout()) -> ok | {error, reason()}.
send(ConnectionHandler, ChannelId, Type, Data, TimeOut) ->
ssh_connection_handler:send(ConnectionHandler, ChannelId,
Type, Data, TimeOut).
%%--------------------------------------------------------------------
--spec send_eof(connection_ref(), channel_id()) -> ok | {error, closed}.
+-spec send_eof(ConnectionRef, ChannelId) -> ok | {error, closed} when
+ ConnectionRef :: ssh:connection_ref(),
+ ChannelId :: ssh:channel_id().
%%
%%
%% Description: Sends eof on the channel