OSDN Git Service

Merge branch 'master' of scm.dev.nokia.troll.no:creator/mainline
[qt-creator-jp/qt-creator-jp.git] / src / plugins / coreplugin / ssh / sshconnection.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** Commercial Usage
10 **
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.
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 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
27 **
28 **************************************************************************/
29
30 #ifndef SSHCONNECTION_H
31 #define SSHCONNECTION_H
32
33 #include "ssherrors.h"
34
35 #include <coreplugin/core_global.h>
36
37 #include <QtCore/QByteArray>
38 #include <QtCore/QObject>
39 #include <QtCore/QSharedPointer>
40 #include <QtCore/QString>
41
42 namespace Core {
43 class SftpChannel;
44 class SshRemoteProcess;
45
46 namespace Internal {
47 class SshConnectionPrivate;
48 } // namespace Internal
49
50 struct CORE_EXPORT SshConnectionParameters
51 {
52     enum ProxyType { DefaultProxy, NoProxy };
53     SshConnectionParameters(ProxyType proxyType);
54
55     QString host;
56     QString uname;
57     QString pwd;
58     QString privateKeyFile;
59     int timeout;
60     enum AuthType { AuthByPwd, AuthByKey } authType;
61     quint16 port;
62     ProxyType proxyType;
63 };
64
65 CORE_EXPORT bool operator==(const SshConnectionParameters &p1, const SshConnectionParameters &p2);
66 CORE_EXPORT bool operator!=(const SshConnectionParameters &p1, const SshConnectionParameters &p2);
67
68 /*
69  * This class provides an SSH connection, implementing protocol version 2.0
70  * It can spawn channels for remote execution and SFTP operations (version 3).
71  * It operates asynchronously (non-blocking) and is not thread-safe.
72  */
73 class CORE_EXPORT SshConnection : public QObject
74 {
75     Q_OBJECT
76     Q_DISABLE_COPY(SshConnection)
77 public:
78     enum State { Unconnected, Connecting, Connected };
79     typedef QSharedPointer<SshConnection> Ptr;
80
81     static Ptr create();
82
83     void connectToHost(const SshConnectionParameters &serverInfo);
84     void disconnectFromHost();
85     State state() const;
86     SshError errorState() const;
87     QString errorString() const;
88     SshConnectionParameters connectionParameters() const;
89     ~SshConnection();
90
91     QSharedPointer<SshRemoteProcess> createRemoteProcess(const QByteArray &command);
92     QSharedPointer<SftpChannel> createSftpChannel();
93
94 signals:
95     void connected();
96     void disconnected();
97     void dataAvailable(const QString &message);
98     void error(Core::SshError);
99
100 private:
101     SshConnection();
102
103     Internal::SshConnectionPrivate *d;
104 };
105
106 } // namespace Internal
107
108 #endif // SSHCONNECTION_H