public abstract class SessionChannelNG extends com.sshtools.synergy.ssh.ChannelNG<SshServerContext> implements com.sshtools.common.nio.IdleStateListener, com.sshtools.common.ssh.SessionChannelServer
This class provides an abstract session, it handles all the requests defined in the SSH Connection protocol for a session channel and passes the request to the concrete implementation through its abstract methods.
When creating a session implementation your #processStdinData(byte[])
will receive data from the client and process as session input. To send
stdout data for your session you should use the
sendStdoutData(byte[])
method and any sdterr output should be send
using sendStderrData(byte[])
method.
As the server uses an asynchronous framework expensive blocking operations SHOULD NOT be performed within your session as this will cause a deadlock on the server.
The basic process of establishing a session is this
#sendExitStatus(int)
.Modifier and Type | Field and Description |
---|---|
static int |
SSH_EXTENDED_DATA_STDERR |
Constructor and Description |
---|
SessionChannelNG(com.sshtools.common.ssh.SshConnection con) |
SessionChannelNG(com.sshtools.common.ssh.SshConnection con,
boolean autoConsume) |
Modifier and Type | Method and Description |
---|---|
protected abstract boolean |
allocatePseudoTerminal(java.lang.String term,
int cols,
int rows,
int width,
int height,
byte[] modes)
If the client requests a pseudo terminal for the session this method will
be invoked before the shell, exec or subsystem is started.
|
protected abstract void |
changeWindowDimensions(int cols,
int rows,
int width,
int height)
When the window (terminal) size changes on the client side, it MAY send
notification in which case this method will be invoked to notify the
session that a change has occurred.
|
protected byte[] |
createChannel() |
void |
disableRawMode() |
void |
enableRawMode() |
protected boolean |
executeCommand(java.lang.String[] args)
Invoked when the user wants to execute a command
|
java.io.OutputStream |
getErrorStream() |
int |
getMaximumWindowSpace() |
int |
getMinimumWindowSpace() |
com.sshtools.common.ssh.Subsystem |
getSubsystem() |
boolean |
idle() |
boolean |
isAgentForwardingRequested() |
boolean |
isIncomingDataHalted() |
boolean |
isSingleSession() |
protected void |
onChannelClosed() |
protected void |
onChannelClosing()
Called when the channel is closing.
|
protected void |
onChannelData(java.nio.ByteBuffer data)
Called when data arrives on the channel.
|
protected void |
onChannelFree()
Free the session and its resources.
|
protected void |
onChannelOpen()
Called once the channel has been opened.
|
protected void |
onChannelOpenConfirmation()
Called when the channel is confirmed as open
|
protected void |
onChannelRequest(java.lang.String type,
boolean wantreply,
byte[] requestdata)
Process session requests and invoke the relevant abstract methods of this
class to handle the requests.
|
protected void |
onExtendedData(java.nio.ByteBuffer data,
int type)
Called when extended data arrives on the channel - for a session channel
this would not normally be called.
|
protected void |
onRemoteEOF()
The remote side has reported EOF so no more data will be received.
|
protected void |
onSessionData(java.nio.ByteBuffer data) |
void |
onSessionOpen() |
protected byte[] |
openChannel(byte[] data) |
protected abstract void |
processSignal(java.lang.String signal)
A signal can be delivered to the process by the client.
|
protected boolean |
requestAgentForwarding(java.lang.String requestType)
Implement this method to support agent forwarding.
|
void |
sendStderrData(byte[] data)
Send stderr data to the remote client.
|
void |
sendStderrData(byte[] data,
int off,
int len)
Sends stderr data to the remote client.
|
void |
sendStdoutData(byte[] data)
Sends stdout data to the remote client
|
void |
sendStdoutData(byte[] data,
int off,
int len)
Sends stdout data to the remote client.
|
abstract boolean |
setEnvironmentVariable(java.lang.String name,
java.lang.String value)
If the client requests that an environment variable be set this method
will be invoked.
|
void |
setSingleSession(boolean singleSession) |
protected abstract boolean |
startShell()
Invoked when the user wants to start a shell.
|
protected boolean |
startSubsystem(java.lang.String name) |
addEventListener, canClose, checkWindowSpace, clearIdleState, close, close, createCache, evaluateWindowSpace, getChannelType, getCloseFuture, getConnection, getConnectionProtocol, getContext, getInputStream, getLastActivity, getLocalId, getLocalPacket, getLocalWindow, getMaxiumRemotePacketSize, getMaxiumRemoteWindowSize, getOpenFuture, getOutputStream, getRemoteId, getRemotePacket, getRemoteWindow, getSessionIdentifier, getTimeout, haltIncomingData, isClosed, isClosing, isConnected, isLocalEOF, isOpen, isRemoteEOF, log, log, log, logMessage, onChannelError, onChannelOpenFailure, onLocalEOF, onRemoteClose, onWindowAdjust, processChannelRequestResponse, registerExtendedDataType, resetIdleState, resumeIncomingData, sendChannelDataAndBlock, sendChannelDataAndBlock, sendChannelDataAndBlock, sendChannelDataAndBlock, sendChannelDataAndBlock, sendChannelDataAndBlock, sendChannelRequest, sendChannelRequest, sendData, sendEOF, sendExtendedData, sendExtendedData, sendRequestResponse, sendWindowAdjust, sendWindowAdjust, setTimeout
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public static final int SSH_EXTENDED_DATA_STDERR
public SessionChannelNG(com.sshtools.common.ssh.SshConnection con)
public SessionChannelNG(com.sshtools.common.ssh.SshConnection con, boolean autoConsume)
public boolean isSingleSession()
public void setSingleSession(boolean singleSession)
protected void onChannelClosed()
onChannelClosed
in class com.sshtools.synergy.ssh.ChannelNG<SshServerContext>
public void enableRawMode()
enableRawMode
in interface com.sshtools.common.ssh.SessionChannelServer
public void disableRawMode()
disableRawMode
in interface com.sshtools.common.ssh.SessionChannelServer
public com.sshtools.common.ssh.Subsystem getSubsystem()
protected final byte[] createChannel() throws java.io.IOException
createChannel
in class com.sshtools.synergy.ssh.ChannelNG<SshServerContext>
java.io.IOException
public java.io.OutputStream getErrorStream()
getErrorStream
in interface com.sshtools.common.ssh.SessionChannelServer
public boolean isAgentForwardingRequested()
protected boolean requestAgentForwarding(java.lang.String requestType)
protected abstract boolean allocatePseudoTerminal(java.lang.String term, int cols, int rows, int width, int height, byte[] modes)
term
- cols
- rows
- width
- height
- modes
- protected abstract void changeWindowDimensions(int cols, int rows, int width, int height)
cols
- rows
- width
- height
- protected abstract void processSignal(java.lang.String signal)
signal
- public abstract boolean setEnvironmentVariable(java.lang.String name, java.lang.String value)
setEnvironmentVariable
in interface com.sshtools.common.ssh.SessionChannelServer
name
- value
- protected abstract boolean startShell()
protected boolean executeCommand(java.lang.String[] args)
cmd
- protected void onChannelOpen()
onChannelOpen
in class com.sshtools.synergy.ssh.ChannelNG<SshServerContext>
public boolean idle()
idle
in interface com.sshtools.common.nio.IdleStateListener
protected void onChannelRequest(java.lang.String type, boolean wantreply, byte[] requestdata)
onChannelRequest
in class com.sshtools.synergy.ssh.ChannelNG<SshServerContext>
type
- Stringwantreply
- booleanrequestdata
- byte[]protected void onChannelOpenConfirmation()
onChannelOpenConfirmation
in class com.sshtools.synergy.ssh.ChannelNG<SshServerContext>
protected void onRemoteEOF()
onRemoteEOF
in class com.sshtools.synergy.ssh.ChannelNG<SshServerContext>
protected void onChannelFree()
onChannelFree
in class com.sshtools.synergy.ssh.ChannelNG<SshServerContext>
protected void onChannelClosing()
onChannelClosing
in class com.sshtools.synergy.ssh.ChannelNG<SshServerContext>
protected final void onChannelData(java.nio.ByteBuffer data)
onChannelData
in class com.sshtools.synergy.ssh.ChannelNG<SshServerContext>
data
- byte[]protected void onSessionData(java.nio.ByteBuffer data)
protected void onExtendedData(java.nio.ByteBuffer data, int type)
onExtendedData
in class com.sshtools.synergy.ssh.ChannelNG<SshServerContext>
data
- byte[]type
- intpublic void sendStdoutData(byte[] data, int off, int len) throws java.io.IOException
data
- off
- len
- java.io.IOException
public void sendStdoutData(byte[] data) throws java.io.IOException
data
- java.io.IOException
public void sendStderrData(byte[] data, int off, int len) throws java.io.IOException
data
- off
- len
- java.io.IOException
public void sendStderrData(byte[] data) throws java.io.IOException
data
- java.io.IOException
protected final byte[] openChannel(byte[] data) throws com.sshtools.common.nio.WriteOperationRequest, com.sshtools.common.ssh.ChannelOpenException
openChannel
in class com.sshtools.synergy.ssh.ChannelNG<SshServerContext>
com.sshtools.common.nio.WriteOperationRequest
com.sshtools.common.ssh.ChannelOpenException
public boolean isIncomingDataHalted()
isIncomingDataHalted
in class com.sshtools.synergy.ssh.ChannelNG<SshServerContext>
public int getMaximumWindowSpace()
getMaximumWindowSpace
in interface com.sshtools.common.ssh.SessionChannel
public int getMinimumWindowSpace()
getMinimumWindowSpace
in interface com.sshtools.common.ssh.SessionChannel
public void onSessionOpen()
onSessionOpen
in interface com.sshtools.common.ssh.SessionChannel
protected boolean startSubsystem(java.lang.String name)
Copyright © 2021. All rights reserved.