1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
28 **************************************************************************/
30 #ifndef SSHCHANNEL_P_H
31 #define SSHCHANNEL_P_H
33 #include <QtCore/QByteArray>
34 #include <QtCore/QObject>
35 #include <QtCore/QString>
37 QT_FORWARD_DECLARE_CLASS(QTimer);
42 struct SshChannelExitSignal;
43 struct SshChannelExitStatus;
44 class SshIncomingPacket;
45 class SshSendFacility;
47 class AbstractSshChannel : public QObject
52 Inactive, SessionRequested, SessionEstablished, CloseRequested, Closed
55 ChannelState channelState() const { return m_state; }
56 void setChannelState(ChannelState state);
58 void setError(const QString &error) { m_errorString = error; }
59 QString errorString() const { return m_errorString; }
61 quint32 localChannelId() const { return m_localChannel; }
62 quint32 remoteChannel() const { return m_remoteChannel; }
64 virtual void handleChannelSuccess()=0;
65 virtual void handleChannelFailure()=0;
67 virtual void closeHook()=0;
69 void handleOpenSuccess(quint32 remoteChannelId, quint32 remoteWindowSize,
70 quint32 remoteMaxPacketSize);
71 void handleOpenFailure(const QString &reason);
72 void handleWindowAdjust(quint32 bytesToAdd);
73 void handleChannelEof();
74 void handleChannelClose();
75 void handleChannelData(const QByteArray &data);
76 void handleChannelExtendedData(quint32 type, const QByteArray &data);
77 void handleChannelRequest(const SshIncomingPacket &packet);
79 void requestSessionStart();
80 void sendData(const QByteArray &data);
83 virtual ~AbstractSshChannel();
85 static const int ReplyTimeout = 10000; // milli seconds
91 AbstractSshChannel(quint32 channelId, SshSendFacility &sendFacility);
93 quint32 maxDataSize() const;
94 void checkChannelActive();
96 SshSendFacility &m_sendFacility;
97 QTimer * const m_timeoutTimer;
100 virtual void handleOpenSuccessInternal()=0;
101 virtual void handleOpenFailureInternal()=0;
102 virtual void handleChannelDataInternal(const QByteArray &data)=0;
103 virtual void handleChannelExtendedDataInternal(quint32 type,
104 const QByteArray &data)=0;
105 virtual void handleExitStatus(const SshChannelExitStatus &exitStatus)=0;
106 virtual void handleExitSignal(const SshChannelExitSignal &signal)=0;
108 void setState(ChannelState newState);
109 void flushSendBuffer();
110 int handleChannelOrExtendedChannelData(const QByteArray &data);
112 const quint32 m_localChannel;
113 quint32 m_remoteChannel;
114 quint32 m_localWindowSize;
115 quint32 m_remoteWindowSize;
116 quint32 m_remoteMaxPacketSize;
117 ChannelState m_state;
118 QByteArray m_sendBuffer;
119 QString m_errorString;
122 } // namespace Internal
125 #endif // SSHCHANNEL_P_H