1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
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 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #ifndef SSHCONNECTION_P_H
35 #define SSHCONNECTION_P_H
37 #include "sshconnection.h"
38 #include "sshexception_p.h"
39 #include "sshincomingpacket_p.h"
40 #include "sshremoteprocess.h"
41 #include "sshsendfacility_p.h"
43 #include <QtCore/QHash>
44 #include <QtCore/QList>
45 #include <QtCore/QObject>
46 #include <QtCore/QPair>
47 #include <QtCore/QScopedPointer>
48 #include <QtCore/QTimer>
54 namespace Botan { class Exception; }
60 class SshChannelManager;
62 // NOTE: When you add stuff here, don't forget to update m_packetHandlers.
63 enum SshStateInternal {
64 SocketUnconnected, // initial and after disconnect
65 SocketConnecting, // After connectToHost()
66 SocketConnected, // After socket's connected() signal
67 KeyExchangeStarted, // After server's KEXINIT message
68 KeyExchangeSuccess, // After server's DH_REPLY message
69 UserAuthServiceRequested,
72 ConnectionEstablished // After service has been started
76 class SshConnectionPrivate : public QObject
79 friend class Core::SshConnection;
81 SshConnectionPrivate(SshConnection *conn);
82 ~SshConnectionPrivate();
84 void connectToHost(const SshConnectionParameters &serverInfo);
85 void closeConnection(SshErrorCode sshError, SshError userError,
86 const QByteArray &serverErrorString, const QString &userErrorString);
87 QSharedPointer<SshRemoteProcess> createRemoteProcess(const QByteArray &command);
88 QSharedPointer<SftpChannel> createSftpChannel();
89 SshStateInternal state() const { return m_state; }
90 SshError error() const { return m_error; }
91 QString errorString() const { return m_errorString; }
96 void dataAvailable(const QString &message);
97 void error(Core::SshError);
100 Q_SLOT void handleSocketConnected();
101 Q_SLOT void handleIncomingData();
102 Q_SLOT void handleSocketError();
103 Q_SLOT void handleSocketDisconnected();
104 Q_SLOT void handleTimeout();
106 void handleServerId();
107 void handlePackets();
108 void handleCurrentPacket();
109 void handleKeyExchangeInitPacket();
110 void handleKeyExchangeReplyPacket();
111 void handleNewKeysPacket();
112 void handleServiceAcceptPacket();
113 void handlePasswordExpiredPacket();
114 void handleUserAuthSuccessPacket();
115 void handleUserAuthFailurePacket();
116 void handleUserAuthBannerPacket();
117 void handleGlobalRequest();
118 void handleDebugPacket();
119 void handleChannelRequest();
120 void handleChannelOpen();
121 void handleChannelOpenFailure();
122 void handleChannelOpenConfirmation();
123 void handleChannelSuccess();
124 void handleChannelFailure();
125 void handleChannelWindowAdjust();
126 void handleChannelData();
127 void handleChannelExtendedData();
128 void handleChannelEof();
129 void handleChannelClose();
130 void handleDisconnect();
131 bool canUseSocket() const;
133 void sendData(const QByteArray &data);
135 typedef void (SshConnectionPrivate::*PacketHandler)();
136 typedef QList<SshStateInternal> StateList;
137 void setupPacketHandlers();
138 void setupPacketHandler(SshPacketType type, const StateList &states,
139 PacketHandler handler);
141 typedef QPair<StateList, PacketHandler> HandlerInStates;
142 QHash<SshPacketType, HandlerInStates> m_packetHandlers;
144 QTcpSocket *m_socket;
145 SshStateInternal m_state;
146 SshIncomingPacket m_incomingPacket;
147 SshSendFacility m_sendFacility;
148 SshChannelManager * const m_channelManager;
149 SshConnectionParameters m_connParams;
150 QByteArray m_incomingData;
152 QString m_errorString;
153 QScopedPointer<SshKeyExchange> m_keyExchange;
154 QTimer m_timeoutTimer;
155 bool m_ignoreNextPacket;
156 SshConnection *m_conn;
159 } // namespace Internal
162 #endif // SSHCONNECTION_P_H