OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / coreplugin / ssh / sshconnection_p.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef SSHCONNECTION_P_H
35 #define SSHCONNECTION_P_H
36
37 #include "sshconnection.h"
38 #include "sshexception_p.h"
39 #include "sshincomingpacket_p.h"
40 #include "sshremoteprocess.h"
41 #include "sshsendfacility_p.h"
42
43 #include <QtCore/QHash>
44 #include <QtCore/QList>
45 #include <QtCore/QObject>
46 #include <QtCore/QPair>
47 #include <QtCore/QScopedPointer>
48 #include <QtCore/QTimer>
49
50 QT_BEGIN_NAMESPACE
51 class QTcpSocket;
52 QT_END_NAMESPACE
53
54 namespace Botan { class Exception; }
55
56 namespace Core {
57 class SftpChannel;
58
59 namespace Internal {
60 class SshChannelManager;
61
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,
70     UserAuthRequested,
71
72     ConnectionEstablished // After service has been started
73     // ...
74 };
75
76 class SshConnectionPrivate : public QObject
77 {
78     Q_OBJECT
79     friend class Core::SshConnection;
80 public:
81     SshConnectionPrivate(SshConnection *conn);
82     ~SshConnectionPrivate();
83
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; }
92
93 signals:
94     void connected();
95     void disconnected();
96     void dataAvailable(const QString &message);
97     void error(Core::SshError);
98
99 private:
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();
105
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;
132
133     void sendData(const QByteArray &data);
134
135     typedef void (SshConnectionPrivate::*PacketHandler)();
136     typedef QList<SshStateInternal> StateList;
137     void setupPacketHandlers();
138     void setupPacketHandler(SshPacketType type, const StateList &states,
139         PacketHandler handler);
140
141     typedef QPair<StateList, PacketHandler> HandlerInStates;
142     QHash<SshPacketType, HandlerInStates> m_packetHandlers;
143
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;
151     SshError m_error;
152     QString m_errorString;
153     QScopedPointer<SshKeyExchange> m_keyExchange;
154     QTimer m_timeoutTimer;
155     bool m_ignoreNextPacket;
156     SshConnection *m_conn;
157 };
158
159 } // namespace Internal
160 } // namespace Core
161
162 #endif // SSHCONNECTION_P_H