com.maverick.sshd
Class SessionChannel

java.lang.Object
  extended by com.maverick.sshd.Channel
      extended by com.maverick.sshd.SessionChannel
All Implemented Interfaces:
IdleStateListener
Direct Known Subclasses:
UnsupportedSession

public abstract class SessionChannel
extends Channel
implements IdleStateListener

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

Author:
Lee David Painter

Nested Class Summary
 
Nested classes/interfaces inherited from class com.maverick.sshd.Channel
Channel.QueuedData
 
Field Summary
protected  int MAX_WINDOW_SPACE
           
protected  int MIN_WINDOW_SPACE
           
 
Fields inherited from class com.maverick.sshd.Channel
connection, localwindow, localWindowLock
 
Constructor Summary
SessionChannel()
           
 
Method Summary
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()
          set the max window space as a multiple of the minimum window space.
protected  void evaluateWindowSpace(int remaining)
          Called to evaluate the window space available.
protected abstract  boolean executeCommand(java.lang.String cmd)
          Invoked when the user wants to execute a command
 java.lang.String getSessionIdentifier()
          Get the session id for the current connection.
 void haltIncomingData()
           
 boolean idle()
          Process an idle event.
protected  void onChannelClosing()
          Called when the channel is closing.
protected  void onChannelData(byte[] 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(byte[] 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 abstract  void onSessionOpen()
          Called once the session is open and data can be sent/received.
protected  byte[] openChannel(byte[] data)
          Called when the channel is being opened.
protected abstract  void processSignal(java.lang.String signal)
          A signal can be delivered to the process by the client.
protected abstract  void processStdinData(byte[] data)
          Data has arrived on the session's stdin stream.
 void resumeIncomingData()
           
 void sendChannelDataWithBuffering(byte[] data, int off, int len)
          Send channel data to the remote side of the channel and block until the data has been sent.
protected  void sendExitStatus(int exitcode)
          When a command or shell exits its possible to send the client the exit code of the process.
 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.
protected 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.
protected abstract  boolean startShell()
          Invoked when the user wants to start a shell.
 
Methods inherited from class com.maverick.sshd.Channel
addEventListener, addInputListener, addOutputListener, canClose, clearIdleState, close, getChannelType, getConnection, getContext, getLocalId, getLocalPacket, getLocalWindow, getQueueSize, getRemoteId, getRemotePacket, getRemoteWindow, hasQueuedData, isClosed, isClosing, isEOF, isOpen, onChannelClosed, onChannelOpenFailure, onLocalEOF, onRemoteClose, onWindowAdjust, queueSize, registerExtendedData, resetIdleState, sendChannelData, sendChannelData, sendChannelData, sendChannelData, sendChannelDataWithBuffering, sendChannelRequest, sendEOF, sendExtendedData, sendExtendedData, sendRequestResponse, sendWindowAdjust
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_WINDOW_SPACE

protected int MAX_WINDOW_SPACE

MIN_WINDOW_SPACE

protected int MIN_WINDOW_SPACE
Constructor Detail

SessionChannel

public SessionChannel()
Method Detail

createChannel

protected final byte[] createChannel()
                              throws java.io.IOException
set the max window space as a multiple of the minimum window space. The default minimum window space is the same as the packet size

Specified by:
createChannel in class Channel
Parameters:
minSizeMultiple -
Returns:
Throws:
java.io.IOException

allocatePseudoTerminal

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.

Parameters:
term -
cols -
rows -
width -
height -
modes -
Returns:
boolean

changeWindowDimensions

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.

Parameters:
cols -
rows -
width -
height -

processSignal

protected abstract void processSignal(java.lang.String signal)
A signal can be delivered to the process by the client. If a signal is received this method will be invoked so that the session may evaluate and take the required action.

Parameters:
signal -

setEnvironmentVariable

protected 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.

Parameters:
name -
value -
Returns:
true if the variable has been set, otherwise false

startShell

protected abstract boolean startShell()
Invoked when the user wants to start a shell.

Returns:
true if the shell has been started, otherwise false

executeCommand

protected abstract boolean executeCommand(java.lang.String cmd)
Invoked when the user wants to execute a command

Parameters:
cmd -
Returns:
true if the cmd has been executed, otherwise false

processStdinData

protected abstract void processStdinData(byte[] data)
Data has arrived on the session's stdin stream.

Parameters:
data -

onSessionOpen

protected abstract void onSessionOpen()
Called once the session is open and data can be sent/received. This event happens once the user has either started the shell or executed a command.


onChannelOpen

protected void onChannelOpen()
Called once the channel has been opened.

Specified by:
onChannelOpen in class Channel

idle

public boolean idle()
Description copied from interface: IdleStateListener
Process an idle event.

Specified by:
idle in interface IdleStateListener
Returns:
true if this listener should be cancelled.

onChannelRequest

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. If you overide this method make sure that you call the super method.

Specified by:
onChannelRequest in class Channel
Parameters:
type - String
wantreply - boolean
requestdata - byte[]

getSessionIdentifier

public java.lang.String getSessionIdentifier()
Get the session id for the current connection.

Overrides:
getSessionIdentifier in class Channel
Returns:
String

onChannelOpenConfirmation

protected void onChannelOpenConfirmation()
Called when the channel is confirmed as open

Specified by:
onChannelOpenConfirmation in class Channel

onRemoteEOF

protected void onRemoteEOF()
The remote side has reported EOF so no more data will be received. This will force the channel to close. If this behaviour is not required you can override this method

Specified by:
onRemoteEOF in class Channel

onChannelFree

protected void onChannelFree()
Free the session and its resources. If you override this method make sure that you call the super method to ensure that the resources of the abstract class are freed.

Specified by:
onChannelFree in class Channel

onChannelClosing

protected void onChannelClosing()
Called when the channel is closing. If you override this method make sure that you call the super method.

Specified by:
onChannelClosing in class Channel

onChannelData

protected void onChannelData(byte[] data)
Called when data arrives on the channel.

Specified by:
onChannelData in class Channel
Parameters:
data - byte[]

onExtendedData

protected void onExtendedData(byte[] data,
                              int type)
Called when extended data arrives on the channel - for a session channel this would not normally be called.

Specified by:
onExtendedData in class Channel
Parameters:
data - byte[]
type - int

sendStdoutData

public void sendStdoutData(byte[] data,
                           int off,
                           int len)
Sends stdout data to the remote client.

Parameters:
data -
off -
len -

sendChannelDataWithBuffering

public void sendChannelDataWithBuffering(byte[] data,
                                         int off,
                                         int len)
Send channel data to the remote side of the channel and block until the data has been sent. DO NOT call this method if the current thread is the same as the selector thread.

Overrides:
sendChannelDataWithBuffering in class Channel
Parameters:
data - byte[]
off - int
len - int

sendStdoutData

public void sendStdoutData(byte[] data)
Sends stdout data to the remote client

Parameters:
data -

sendStderrData

public void sendStderrData(byte[] data,
                           int off,
                           int len)
Sends stderr data to the remote client.

Parameters:
data -
off -
len -

sendStderrData

public void sendStderrData(byte[] data)
Send stderr data to the remote client.

Parameters:
data -

sendExitStatus

protected void sendExitStatus(int exitcode)
When a command or shell exits its possible to send the client the exit code of the process. Use this method before the channel is closed.

Parameters:
exitcode -

evaluateWindowSpace

protected final void evaluateWindowSpace(int remaining)
Description copied from class: Channel
Called to evaluate the window space available. Send a window adjust message if there if the minimum amount of space is not available.

Specified by:
evaluateWindowSpace in class Channel

haltIncomingData

public void haltIncomingData()

resumeIncomingData

public void resumeIncomingData()

openChannel

protected final byte[] openChannel(byte[] data)
                            throws WriteOperationRequest,
                                   ChannelOpenException
Description copied from class: Channel
Called when the channel is being opened. You can retrun data to be sent in the channel open confirmation message, or null for none.

Specified by:
openChannel in class Channel
Returns:
byte[]
Throws:
WriteOperationRequest
ChannelOpenException


Copyright © 2003-2008 SSHTools LTD. All Rights Reserved.