public class ChannelSession extends AbstractServerChannel
Modifier and Type | Class and Description |
---|---|
class |
ChannelSession.CommandCloseable |
AbstractChannel.GracefulChannelCloseable, AbstractChannel.GracefulState
AbstractCloseable.State
AttributeRepository.AttributeKey<T>
Modifier and Type | Field and Description |
---|---|
protected ChannelAsyncOutputStream |
asyncErr |
protected ChannelAsyncOutputStream |
asyncOut |
protected CloseFuture |
commandExitFuture |
protected Command |
commandInstance |
protected AtomicBoolean |
commandStarted |
static List<ChannelRequestHandler> |
DEFAULT_HANDLERS |
protected StandardEnvironment |
env |
protected OutputStream |
err |
protected Buffer |
extendedDataBuffer |
protected ChannelDataReceiver |
extendedDataWriter |
protected OutputStream |
out |
protected ChannelDataReceiver |
receiver |
protected Buffer |
receiverBuffer |
protected String |
type |
exitStatusSent
channelListenerProxy, channelListeners, closeSignaled, eofReceived, eofSent, gracefulFuture, gracefulState, initialized, RESPONSE_BUFFER_GROWTH_FACTOR, service, unregisterSignaled
closeFuture, futureLock, state
log
CHANNEL_EXEC, CHANNEL_SHELL, CHANNEL_SUBSYSTEM
EMPTY
NONE
Constructor and Description |
---|
ChannelSession() |
ChannelSession(Collection<? extends RequestHandler<Channel>> handlers) |
Modifier and Type | Method and Description |
---|---|
protected void |
addEnvVariable(String name,
String value) |
protected void |
closeImmediately0() |
protected void |
closeShell(int exitValue,
boolean closeImmediately) |
protected void |
doWriteData(byte[] data,
int off,
long len) |
protected void |
doWriteExtendedData(byte[] data,
int off,
long len) |
StandardEnvironment |
getEnvironment() |
protected Closeable |
getInnerCloseable() |
protected int |
getPtyModeValue(PtyMode mode) |
ServerSession |
getSession() |
protected RequestHandler.Result |
handleAgentForwarding(String requestType,
Buffer buffer,
boolean wantReply) |
protected RequestHandler.Result |
handleAgentForwardingParsed(String requestType) |
protected RequestHandler.Result |
handleBreak(Buffer buffer,
boolean wantReply) |
protected RequestHandler.Result |
handleBreakParsed(long breakLength) |
protected RequestHandler.Result |
handleEnv(Buffer buffer,
boolean wantReply) |
protected RequestHandler.Result |
handleEnvParsed(String name,
String value) |
void |
handleEof()
Invoked when
SSH_MSG_CHANNEL_EOF received |
protected RequestHandler.Result |
handleExec(String request,
Buffer buffer,
boolean wantReply) |
protected RequestHandler.Result |
handleExecParsed(String request,
String commandLine) |
protected RequestHandler.Result |
handleInternalRequest(String requestType,
boolean wantReply,
Buffer buffer)
Called by
AbstractChannel.handleUnknownChannelRequest(String, boolean, Buffer) in order to allow channel request
handling if none of the registered handlers processed the request - last chance. |
protected RequestHandler.Result |
handlePtyReq(Buffer buffer,
boolean wantReply) |
protected RequestHandler.Result |
handlePtyReqParsed(String term,
int tColumns,
int tRows,
int tWidth,
int tHeight,
Map<PtyMode,Integer> ptyModes) |
protected RequestHandler.Result |
handleShell(String request,
Buffer buffer,
boolean wantReply) |
protected RequestHandler.Result |
handleShellParsed(String request) |
protected RequestHandler.Result |
handleSignal(Buffer buffer,
boolean wantReply) |
protected RequestHandler.Result |
handleSignalParsed(String name) |
protected RequestHandler.Result |
handleSubsystem(String request,
Buffer buffer,
boolean wantReply) |
protected RequestHandler.Result |
handleSubsystemParsed(String request,
String subsystem) |
void |
handleWindowAdjust(Buffer buffer)
Invoked when
SSH_MSG_CHANNEL_WINDOW_ADJUST received |
protected RequestHandler.Result |
handleWindowChange(Buffer buffer,
boolean wantReply) |
protected RequestHandler.Result |
handleWindowChangeParsed(int tColumns,
int tRows,
int tWidth,
int tHeight) |
protected RequestHandler.Result |
handleX11Forwarding(String requestType,
Buffer buffer,
boolean wantReply) |
protected RequestHandler.Result |
handleX11ForwardingParsed(String requestType,
ServerSession session,
boolean singleConnection,
String authProtocol,
String authCookie,
int screenId) |
protected boolean |
mayWrite() |
protected RequestHandler.Result |
prepareChannelCommand(String request,
Command cmd) |
protected Command |
prepareCommand(String requestType,
Command command)
Called by
prepareChannelCommand(String, Command) in order to set up the command's streams, session,
file-system, exit callback, etc.. |
protected IoWriteFuture |
sendResponse(Buffer buffer,
String req,
RequestHandler.Result result,
boolean wantReply) |
void |
setDataReceiver(ChannelDataReceiver receiver)
For
Command to install ChannelDataReceiver . |
void |
setExtendedDataWriter(ChannelDataReceiver extendedDataWriter)
A special
ChannelDataReceiver that can be used to receive data sent as "extended" - usually
STDERR. |
doInit, handleOpenFailure, handleOpenSuccess, open, sendExitStatus
addChannelListener, addPendingRequest, addRequestHandler, attributeKeys, clearAttributes, computeAttributeIfAbsent, configureWindow, getAttribute, getAttributesCount, getChannelId, getChannelListenerProxy, getChannelStreamWriterResolver, getExecutorService, getLocalWindow, getParentPropertyResolver, getProperties, getRecipient, getRemoteWindow, getRequestHandlers, handleChannelRegistrationResult, handleChannelRequest, handleChannelUnregistration, handleClose, handleData, handleExtendedData, handleFailure, handleRequest, handleSuccess, handleUnknownChannelRequest, init, invokeChannelSignaller, isEofSent, isEofSignalled, isInitialized, notifyStateChanged, notifyStateChanged, preClose, removeAttribute, removeChannelListener, removePendingRequest, removeRequestHandler, resolveChannelStreamWriterResolver, sendEof, sendWindowAdjust, setAttribute, setChannelStreamWriterResolver, setRecipient, signalChannelClosed, signalChannelClosed, signalChannelInitialized, signalChannelInitialized, signalChannelOpenFailure, signalChannelOpenFailure, signalChannelOpenSuccess, signalChannelOpenSuccess, toString, validateIncomingDataSize, writePacket
doCloseGracefully, doCloseImmediately
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, removeCloseFutureListener
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getServerSession
addRequestHandler, addRequestHandlers, getLocalWindow, getRecipient, getRemoteWindow, getRequestHandlers, handleChannelRegistrationResult, handleChannelUnregistration, handleClose, handleData, handleExtendedData, handleFailure, handleRequest, handleSuccess, init, isEofSignalled, isInitialized, removeRequestHandler, removeRequestHandlers, resolveAttribute, resolveAttribute, writePacket
getSessionContext
getChannelId
addChannelListener, getChannelListenerProxy, removeChannelListener
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringProperty, isEmpty, isEmpty
clearAttributes, computeAttributeIfAbsent, removeAttribute, setAttribute
attributeKeys, getAttribute, getAttributesCount, ofAttributesMap, ofKeyValuePair
getChannelStreamWriterResolver, resolveChannelStreamWriter, resolveChannelStreamWriterResolver, setChannelStreamWriterResolver
addCloseFutureListener, close, close, close, getMaxCloseWaitTime, isClosed, isClosing, isOpen, removeCloseFutureListener
public static final List<ChannelRequestHandler> DEFAULT_HANDLERS
protected String type
protected ChannelAsyncOutputStream asyncOut
protected ChannelAsyncOutputStream asyncErr
protected OutputStream out
protected OutputStream err
protected Command commandInstance
protected ChannelDataReceiver receiver
protected ChannelDataReceiver extendedDataWriter
protected Buffer receiverBuffer
protected Buffer extendedDataBuffer
protected final AtomicBoolean commandStarted
protected final StandardEnvironment env
protected final CloseFuture commandExitFuture
public ChannelSession()
public ChannelSession(Collection<? extends RequestHandler<Channel>> handlers)
public ServerSession getSession()
getSession
in interface SessionHolder<Session>
getSession
in class AbstractChannel
public void handleWindowAdjust(Buffer buffer) throws IOException
Channel
SSH_MSG_CHANNEL_WINDOW_ADJUST
receivedhandleWindowAdjust
in class AbstractChannel
buffer
- The rest of the message data Buffer
after decoding the channel identifiersIOException
- If failed to handle the messageprotected boolean mayWrite()
mayWrite
in class AbstractChannel
protected Closeable getInnerCloseable()
getInnerCloseable
in class AbstractChannel
protected void closeImmediately0()
public void handleEof() throws IOException
Channel
SSH_MSG_CHANNEL_EOF
receivedhandleEof
in class AbstractChannel
IOException
- If failed to handle the messageprotected void doWriteData(byte[] data, int off, long len) throws IOException
doWriteData
in class AbstractChannel
IOException
protected void doWriteExtendedData(byte[] data, int off, long len) throws IOException
doWriteExtendedData
in class AbstractChannel
IOException
protected RequestHandler.Result handleInternalRequest(String requestType, boolean wantReply, Buffer buffer) throws IOException
AbstractChannel
AbstractChannel.handleUnknownChannelRequest(String, boolean, Buffer)
in order to allow channel request
handling if none of the registered handlers processed the request - last chance.handleInternalRequest
in class AbstractChannel
requestType
- The request typewantReply
- Whether reply is requestedbuffer
- The Buffer
containing extra request-specific datanull
or Unsupported
and reply is required then a
failure message will be sentIOException
- If failed to process the request internallyprotected IoWriteFuture sendResponse(Buffer buffer, String req, RequestHandler.Result result, boolean wantReply) throws IOException
sendResponse
in class AbstractChannel
IOException
protected RequestHandler.Result handleEnv(Buffer buffer, boolean wantReply) throws IOException
IOException
protected RequestHandler.Result handleEnvParsed(String name, String value) throws IOException
IOException
protected RequestHandler.Result handlePtyReq(Buffer buffer, boolean wantReply) throws IOException
IOException
protected RequestHandler.Result handlePtyReqParsed(String term, int tColumns, int tRows, int tWidth, int tHeight, Map<PtyMode,Integer> ptyModes) throws IOException
IOException
protected RequestHandler.Result handleWindowChange(Buffer buffer, boolean wantReply) throws IOException
IOException
protected RequestHandler.Result handleWindowChangeParsed(int tColumns, int tRows, int tWidth, int tHeight) throws IOException
IOException
protected RequestHandler.Result handleSignal(Buffer buffer, boolean wantReply) throws IOException
IOException
protected RequestHandler.Result handleSignalParsed(String name) throws IOException
IOException
protected RequestHandler.Result handleBreak(Buffer buffer, boolean wantReply) throws IOException
IOException
protected RequestHandler.Result handleBreakParsed(long breakLength) throws IOException
IOException
protected RequestHandler.Result handleShell(String request, Buffer buffer, boolean wantReply) throws IOException
IOException
protected RequestHandler.Result handleShellParsed(String request) throws IOException
IOException
protected RequestHandler.Result handleExec(String request, Buffer buffer, boolean wantReply) throws IOException
IOException
protected RequestHandler.Result handleExecParsed(String request, String commandLine) throws IOException
IOException
protected RequestHandler.Result handleSubsystem(String request, Buffer buffer, boolean wantReply) throws IOException
IOException
protected RequestHandler.Result handleSubsystemParsed(String request, String subsystem) throws IOException
IOException
protected RequestHandler.Result prepareChannelCommand(String request, Command cmd) throws IOException
IOException
public void setDataReceiver(ChannelDataReceiver receiver)
Command
to install ChannelDataReceiver
. When you do this,
CommandDirectInputStreamAware.setInputStream(java.io.InputStream)
or
AsyncCommandInputStreamAware.setIoInputStream(org.apache.sshd.common.io.IoInputStream)
will no longer be invoked. If you call this method from Command#start(ChannelSession, Environment)
, the
input stream you received in CommandDirectInputStreamAware.setInputStream(java.io.InputStream)
will not read any data.receiver
- The ChannelDataReceiver
instancepublic void setExtendedDataWriter(ChannelDataReceiver extendedDataWriter)
ChannelDataReceiver
that can be used to receive data sent as "extended" - usually
STDERR. Note: by default any such data sent to the channel session causes an exception, but specific
implementations may choose to register such a receiver (e.g., for custom usage of the STDERR stream). A good
place in the code to register such a writer would be in commands that also implement ChannelSessionAware
.extendedDataWriter
- The ChannelDataReceiver
.protected Command prepareCommand(String requestType, Command command) throws IOException
prepareChannelCommand(String, Command)
in order to set up the command's streams, session,
file-system, exit callback, etc..requestType
- The request that caused the command to be createdcommand
- The created Command
- may be null
null
then the request that initially caused the
creation of the command is failed and the original command (if any) destroyed (eventually).
Note: if a different command instance than the input one is returned, then it is up to
the implementor to take care of the wrapping or destruction of the original command instance.IOException
- If failed to prepare the commandprotected int getPtyModeValue(PtyMode mode)
protected RequestHandler.Result handleAgentForwarding(String requestType, Buffer buffer, boolean wantReply) throws IOException
IOException
protected RequestHandler.Result handleAgentForwardingParsed(String requestType) throws IOException
IOException
protected RequestHandler.Result handleX11Forwarding(String requestType, Buffer buffer, boolean wantReply) throws IOException
IOException
protected RequestHandler.Result handleX11ForwardingParsed(String requestType, ServerSession session, boolean singleConnection, String authProtocol, String authCookie, int screenId) throws IOException
IOException
public StandardEnvironment getEnvironment()
protected void closeShell(int exitValue, boolean closeImmediately) throws IOException
IOException
Copyright © 2008–2024 The Apache Software Foundation. All rights reserved.