# ne7ssh_channel.h

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005-2007 by NetSieben Technologies INC                 *
    00003  *   Author: Andrew Useckas                                                *
    00004  *   Email: andrew@netsieben.com                                           *
    00005  *                                                                         *
    00006  *   Windows Port and bugfixes: Keef Aragon <keef@netsieben.com>           *
    00007  *                                                                         *
    00008  *   This program may be distributed under the terms of the Q Public       *
    00009  *   License as defined by Trolltech AS of Norway and appearing in the     *
    00010  *   file LICENSE.QPL included in the packaging of this file.              *
    00011  *                                                                         *
    00012  *   This program is distributed in the hope that it will be useful,       *
    00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                  *
    00015  ***************************************************************************/
    00016
    00017 #ifndef NE7SSH_CHANNEL_H
    00018 #define NE7SSH_CHANNEL_H
    00019
    00020 #include "ne7ssh_types.h"
    00021 #include "ne7ssh_string.h"
    00022
    00023 class ne7ssh_session;
    00024
    00028 class ne7ssh_channel
    00029 {
    00030   private:
    00031     bool eof, closed;
    00032     bool cmdComplete;
    00033     bool shellSpawned;
    00034
    00035 //    static uint32 channelCount;
    00036     ne7ssh_session *session;
    00037     ne7ssh_string inBuffer;
    00038     ne7ssh_string outBuffer;
    00039     ne7ssh_string delayedBuffer;
    00040
    00046     bool handleChannelConfirm ();
    00047
    00054     bool adjustWindow (Botan::SecureVector<Botan::byte>& packet);
    00055
    00062     virtual bool handleData (Botan::SecureVector<Botan::byte>& packet);
    00063
    00069     bool handleExtendedData (Botan::SecureVector<Botan::byte>& packet);
    00070
    00076     bool handleEof (Botan::SecureVector<Botan::byte>& packet);
    00077
    00083     void handleClose (Botan::SecureVector<Botan::byte>& packet);
    00084
    00090     void handleRequest (Botan::SecureVector<Botan::byte>& packet);
    00091
    00097     bool handleDisconnect (Botan::SecureVector<Botan::byte>& packet);
    00098
    00099   protected:
    00100     uint32 windowRecv, windowSend;
    00101
    00102     bool channelOpened;
    00103
    00107     void sendAdjustWindow ();
    00108
    00109   public:
    00114     ne7ssh_channel(ne7ssh_session* _session);
    00115
    00119     virtual ~ne7ssh_channel();
    00120
    00126     uint32 open (uint32 channelID);
    00127
    00131     void getShell ();
    00132
    00138     bool execCmd (const char* cmd);
    00139
    00143     void receive ();
    00144
    00150     bool handleReceived (Botan::SecureVector<Botan::byte>& _packet);
    00151
    00156     void write (Botan::SecureVector<Botan::byte>& data);
    00157
    00161     void sendAll ();
    00162
    00167     bool data2Send () { if (outBuffer.length() || delayedBuffer.length()) return true; else return false; }
    00168
    00173     bool isOpen () { return channelOpened; }
    00174
    00179     bool sendClose ();
    00180
    00185     bool sendEof ();
    00186
    00191     Botan::SecureVector<Botan::byte>& getReceived () { return inBuffer.value(); }
    00192
    00197     bool getCmdComplete () { return cmdComplete; }
    00198
    00203     bool isRemoteShell () { return shellSpawned; }
    00204
    00210     bool adjustRecvWindow (int bufferSize);
    00211
    00216     uint32 getRecvWindow () { return windowRecv; }
    00217
    00222     uint32 getSendWindow () { return windowSend; }
    00223 };
    00224
    00225 #endif