# ne7ssh_channel Class Reference

`#include <ne7ssh_channel.h>`

Inheritance diagram for ne7ssh_channel:

[legend]
Collaboration diagram for ne7ssh_channel:

[legend]

List of all members.

## Public Member Functions
| ne7ssh_channel (ne7ssh_session *_session)
virtual | ~ne7ssh_channel ()
uint32 | open (uint32 channelID)
void | getShell ()
bool | execCmd (const char *cmd)
void | receive ()
bool | handleReceived (Botan::SecureVector< Botan::byte > &_packet)
void | write (Botan::SecureVector< Botan::byte > &data)
void | sendAll ()
bool | data2Send ()
bool | isOpen ()
bool | sendClose ()
bool | sendEof ()
Botan::SecureVector < Botan::byte > & | getReceived ()
bool | getCmdComplete ()
bool | isRemoteShell ()
bool | adjustRecvWindow (int bufferSize)
uint32 | getRecvWindow ()
uint32 | getSendWindow ()
## Protected Member Functions
void | sendAdjustWindow ()
## Protected Attributes
uint32 | windowRecv
uint32 | windowSend
bool | channelOpened
## Private Member Functions
bool | handleChannelConfirm ()
bool | adjustWindow (Botan::SecureVector< Botan::byte > &packet)
virtual bool | handleData (Botan::SecureVector< Botan::byte > &packet)
bool | handleExtendedData (Botan::SecureVector< Botan::byte > &packet)
bool | handleEof (Botan::SecureVector< Botan::byte > &packet)
void | handleClose (Botan::SecureVector< Botan::byte > &packet)
void | handleRequest (Botan::SecureVector< Botan::byte > &packet)
bool | handleDisconnect (Botan::SecureVector< Botan::byte > &packet)
## Private Attributes
bool | eof
bool | closed
bool | cmdComplete
bool | shellSpawned
ne7ssh_session * | session
ne7ssh_string | inBuffer
ne7ssh_string | outBuffer
ne7ssh_string | delayedBuffer

## Detailed Description

Author:
  Andrew Useckas

## Constructor & Destructor Documentation

ne7ssh_channel::ne7ssh_channel | ( | ne7ssh_session * | _session | ) |

ne7ssh_channel class consturctor.

Parameters:

  | _session | Pointer to ne7ssh_session.

ne7ssh_channel::~ne7ssh_channel | ( |  | ) | `[virtual]`

ne7ssh_channel class destructor.

## Member Function Documentation

bool ne7ssh_channel::adjustRecvWindow | ( | int | bufferSize | ) |

Checks if receive window needs adjusting, if so send a window adjust request.

Parameters:

  | bufferSize | Current buffer size.

Returns:
  False on any error, otherwise true.

References sendAdjustWindow().

Referenced by Ne7sshSftp::handleData().

bool ne7ssh_channel::adjustWindow | ( | Botan::SecureVector< Botan::byte > & | packet | ) | `[private]`

This function is used to handle the 'WINDOWS_ADJUST' packet.

It's used to increase our sending window size.

Parameters:

  | packet | Reference to vector containing WINDOW_ADJUST packet.

Returns:
  If parsing of payload is successful, returns true, otherwise false is returned.

References ne7ssh_string::getInt().

Referenced by handleReceived().

bool ne7ssh_channel::data2Send | ( |  | ) | `[inline]`

Checks if there is any data waiting to be sent. Most often called from selectThread via ne7ssh_connection class.

Returns:
  True if there is data to send, otherwise false is returned.

References ne7ssh_string::length().

Referenced by ne7ssh_connection::data2Send().

bool ne7ssh_channel::execCmd | ( | const char * | cmd | ) |

Executes a single command on the remote end and terminates the connection.

Parameters:

  | cmd | Remote command to execute.

Returns:
  True if command if sening of a command succeded. False returned on failure.

References ne7ssh_string::addChar(), ne7ssh_string::addInt(), ne7ssh_string::addString(), ne7ssh_string::clear(), ne7ssh::errors(), ne7ssh_session::getSendChannel(), ne7ssh_session::getSshChannel(), Ne7sshError::push(), ne7ssh_transport::sendPacket(), and ne7ssh_string::value().

Referenced by ne7ssh_connection::sendCmd().

bool ne7ssh_channel::getCmdComplete | ( |  | ) | `[inline]`

When executing a single command with ne7ssh::sendCmd this command is used to determine when remote side finishes the execution.

Returns:
  True if execution of the command is complete. Otherwise false.

Referenced by ne7ssh_connection::getCmdComplete().

Botan::SecureVector<Botan::byte>& ne7ssh_channel::getReceived | ( |  | ) | `[inline]`

Gets last received packet.

Returns:
  Reference to a vector containing the last received packet.

References ne7ssh_string::value().

Referenced by ne7ssh_connection::getReceived().

uint32 ne7ssh_channel::getRecvWindow | ( |  | ) | `[inline]`

Gets the current size of the receive window.

Returns:
  Size of the revceive window.

Referenced by Ne7sshSftp::Ne7sshSftp().

uint32 ne7ssh_channel::getSendWindow | ( |  | ) | `[inline]`

Gets the current size of the send window.

Returns:
  Size of the send window.

Referenced by Ne7sshSftp::Ne7sshSftp().

void ne7ssh_channel::getShell | ( |  | ) |

Requests shell from remote side. Does not wait for or expect a reply. According to SSH specs that's an acceptable behavior.

References ne7ssh_string::addChar(), ne7ssh_string::addInt(), ne7ssh_string::addString(), ne7ssh_string::clear(), ne7ssh_session::getSendChannel(), ne7ssh_transport::sendPacket(), and ne7ssh_string::value().

Referenced by ne7ssh_connection::connectWithKey(), and ne7ssh_connection::connectWithPassword().

bool ne7ssh_channel::handleChannelConfirm | ( |  | ) | `[private]`

This function is used to handle the 'CHANNEL_OPEN_CONFIRMATION' packet.

After parsing the payload, send channel ID is assigned, along with send windows size and maximum packer size.

Returns:
  Always returns true.

References ne7ssh_string::getInt(), ne7ssh_transport::getPacket(), ne7ssh_session::setMaxPacket(), and ne7ssh_session::setSendChannel().

Referenced by open().

void ne7ssh_channel::handleClose | ( | Botan::SecureVector< Botan::byte > & | packet | ) | `[private]`

This function is used to handle the 'CLOSE' packet.

If the close action wasn't initiated on this end, we also send a 'CLOSE' packet to the remote side, prompting the closing of remote side's receiving channel.

Parameters:

  | packet | Reference to vector containing the 'CLOSE' packet.

References sendClose().

Referenced by handleReceived().

bool ne7ssh_channel::handleData | ( | Botan::SecureVector< Botan::byte > & | packet | ) | `[private, virtual]`

This function is used to handle the 'DATA' packet.

It's used to parse the payload, and add received data to the buffer.

Parameters:

  | packet | Reference to vector containing 'DATA' packet.

Returns:
  If parsing of payload is successful, returns true, otherwise false is returned.

Reimplemented in Ne7sshSftp.

References ne7ssh_string::addChar(), ne7ssh_string::addVector(), ne7ssh_string::chop(), ne7ssh::errors(), ne7ssh_string::getInt(), ne7ssh_session::getSshChannel(), ne7ssh_string::getString(), ne7ssh_string::length(), Ne7sshError::push(), and sendAdjustWindow().

Referenced by handleExtendedData(), and handleReceived().

bool ne7ssh_channel::handleDisconnect | ( | Botan::SecureVector< Botan::byte > & | packet | ) | `[private]`

This function is used to handle the 'DISCONNECT' packet.

In normal operation we should not get this packet. Only if some serious error occurs, and makes remote side drop the connection, will this packet be received. And at that point we disconnect right away, and throw an error.

Parameters:

  | packet | Reference to vector containing the 'DISCONNECT' packet.

References ne7ssh::errors(), ne7ssh_session::getSshChannel(), ne7ssh_string::getString(), and Ne7sshError::push().

Referenced by handleReceived().

bool ne7ssh_channel::handleEof | ( | Botan::SecureVector< Botan::byte > & | packet | ) | `[private]`

This function is used to handle the 'EOF' packet.

It's used to close the receiving window and channel.

Parameters:

  | packet | Reference to vector containing EOF packet.

References ne7ssh::errors(), ne7ssh_session::getSshChannel(), Ne7sshError::push(), and sendClose().

Referenced by handleReceived().

bool ne7ssh_channel::handleExtendedData | ( | Botan::SecureVector< Botan::byte > & | packet | ) | `[private]`

This function is used to handle 'EXTENDED_DATA' packet. This packet is mostly used to transmit remote side errors.

Parameters:

  | packet | Reference to vector containing 'EXTENDED_DATA' packet.

Returns:
  If parsing of payload is successful, returns true, otherwise false is returned.

References ne7ssh::errors(), ne7ssh_string::getInt(), ne7ssh_session::getSshChannel(), ne7ssh_string::getString(), handleData(), Ne7sshError::push(), and sendAdjustWindow().

Referenced by handleReceived().

bool ne7ssh_channel::handleReceived | ( | Botan::SecureVector< Botan::byte > & | _packet | ) |

Handle a packet received from remote side.

Parameters:

  | _packet | Reference to a newly received packet.

Returns:
  True if the packet successfully processed. False on any error.

References ne7ssh_string::addVector(), adjustWindow(), ne7ssh::errors(), ne7ssh_string::getByte(), ne7ssh_session::getSshChannel(), handleClose(), handleData(), handleDisconnect(), handleEof(), handleExtendedData(), handleRequest(), Ne7sshError::push(), and ne7ssh_string::value().

Referenced by receive(), Ne7sshSftp::receiveUntil(), Ne7sshSftp::receiveWhile(), and Ne7sshSftp::receiveWindowAdjust().

void ne7ssh_channel::handleRequest | ( | Botan::SecureVector< Botan::byte > & | packet | ) | `[private]`

This function is used to handle the 'REQUEST' packet.

At this point only two requests are supported, namely "exit-signal" and "exit-status". For the most part we ignore this packet, which is safe to do according to SSH specs.

Parameters:

  | packet | Reference to vector containing the 'REQUEST' packet.

References ne7ssh::errors(), ne7ssh_string::getByte(), ne7ssh_string::getInt(), ne7ssh_session::getSshChannel(), ne7ssh_string::getString(), and Ne7sshError::push().

Referenced by handleReceived().

bool ne7ssh_channel::isOpen | ( |  | ) | `[inline]`

Checks if current channel is in an open state.

Returns:
  True if channel is open, otherwise false is returned.

Referenced by ne7ssh_connection::isOpen(), and ne7ssh_connection::sendClose().

bool ne7ssh_channel::isRemoteShell | ( |  | ) | `[inline]`

Determines if the shell has been spawned on the remote side.

Returns:
  True if the shell has been spawned. Otherwise false.

Referenced by ne7ssh_connection::isRemoteShell(), and ne7ssh_connection::startSftp().

uint32 ne7ssh_channel::open | ( | uint32 | channelID | ) |

Requests 'CHANNEL_OPEN' from the remote side.

Parameters:

  | channelID | New receiving channel ID.

Returns:
  Returns new channel ID, or 0 if open fails.

References ne7ssh_string::addChar(), ne7ssh_string::addInt(), ne7ssh_string::addString(), ne7ssh::errors(), handleChannelConfirm(), Ne7sshError::push(), ne7ssh_transport::sendPacket(), ne7ssh_string::value(), and ne7ssh_transport::waitForPacket().

Referenced by ne7ssh_connection::connectWithKey(), and ne7ssh_connection::connectWithPassword().

void ne7ssh_channel::receive | ( |  | ) |

Receives new packet from remote side. This function is mostly used from selectThread.

References ne7ssh_transport::getPacket(), handleReceived(), and ne7ssh_transport::waitForPacket().

Referenced by ne7ssh_connection::handleData().

void ne7ssh_channel::sendAdjustWindow | ( |  | ) | `[protected]`

Request adjustment of the send window size on the remote end, so we can receive more data.

References ne7ssh_string::addChar(), ne7ssh_string::addInt(), ne7ssh_session::getMaxPacket(), ne7ssh_session::getSendChannel(), ne7ssh_transport::sendPacket(), and ne7ssh_string::value().

Referenced by adjustRecvWindow(), handleData(), and handleExtendedData().

void ne7ssh_channel::sendAll | ( |  | ) |

Sends the entire buffer. Most often called from selectThread via ne7ssh_connection class.

References ne7ssh_string::addChar(), ne7ssh_string::addInt(), ne7ssh_string::addVectorField(), ne7ssh_string::clear(), ne7ssh_session::getSendChannel(), ne7ssh_string::length(), ne7ssh_transport::sendPacket(), ne7ssh_string::value(), and write().

Referenced by ne7ssh_connection::sendData().

bool ne7ssh_channel::sendClose | ( |  | ) |

When closing a channel, initiates the closing procedure.

Returns:
  False if sending fails. Otherwise true is returned.

References ne7ssh_string::addChar(), ne7ssh_string::addInt(), ne7ssh_session::getSendChannel(), ne7ssh_transport::sendPacket(), and ne7ssh_string::value().

Referenced by handleClose(), handleEof(), and ne7ssh_connection::sendClose().

bool ne7ssh_channel::sendEof | ( |  | ) |

Send EOF to the remote side.

Returns:
  True if sending succeeds, otherwise false.

References ne7ssh_string::addChar(), ne7ssh_string::addInt(), ne7ssh_session::getSendChannel(), ne7ssh_transport::sendPacket(), and ne7ssh_string::value().

void ne7ssh_channel::write | ( | Botan::SecureVector< Botan::byte > & | data | ) |

Pushes a new command to the buffer where the selectThread will catch and send it.

Parameters:

  | data | Reference to vector containing a command to be added to the buffer.

References ne7ssh_string::addVector(), ne7ssh_string::clear(), ne7ssh_session::getMaxPacket(), ne7ssh_string::length(), and ne7ssh_string::value().

Referenced by sendAll(), and ne7ssh_connection::sendData().

The documentation for this class was generated from the following files:

- ne7ssh_channel.h
- ne7ssh_channel.cpp