#include <ne7ssh_channel.h>
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 |
ne7ssh_channel::ne7ssh_channel | ( | ne7ssh_session * | _session | ) |
ne7ssh_channel class consturctor.
_session | Pointer to ne7ssh_session. |
ne7ssh_channel::~ne7ssh_channel | ( | ) | [virtual] |
ne7ssh_channel class destructor.
bool ne7ssh_channel::adjustRecvWindow | ( | int | bufferSize | ) |
Checks if receive window needs adjusting, if so send a window adjust request.
bufferSize | Current buffer size. |
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.
packet | Reference to vector containing WINDOW_ADJUST packet. |
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.
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.
cmd | Remote command to execute. |
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.
Referenced by ne7ssh_connection::getCmdComplete().
Botan::SecureVector<Botan::byte>& ne7ssh_channel::getReceived | ( | ) | [inline] |
Gets 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.
Referenced by Ne7sshSftp::Ne7sshSftp().
uint32 ne7ssh_channel::getSendWindow | ( | ) | [inline] |
Gets the current 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.
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.
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.
packet | Reference to vector containing 'DATA' packet. |
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.
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.
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.
packet | Reference to vector containing 'EXTENDED_DATA' packet. |
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.
_packet | Reference to a newly received packet. |
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.
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.
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.
Referenced by ne7ssh_connection::isRemoteShell(), and ne7ssh_connection::startSftp().
uint32 ne7ssh_channel::open | ( | uint32 | channelID | ) |
Requests 'CHANNEL_OPEN' from the remote side.
channelID | New receiving channel ID. |
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.
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.
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.
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().