forked from qt-creator/qt-creator
SSH: Implement remote shell support.
Change-Id: Ifcddd930bbf027f4828f8ba01544aca5dea1eeed Reviewed-on: http://codereview.qt.nokia.com/2220 Reviewed-by: Christian Kandeler <christian.kandeler@nokia.com>
This commit is contained in:
@@ -156,6 +156,13 @@ Utils::SshRemoteProcess::Ptr SshChannelManager::createRemoteProcess(const QByteA
|
||||
return proc;
|
||||
}
|
||||
|
||||
Utils::SshRemoteProcess::Ptr SshChannelManager::createRemoteShell()
|
||||
{
|
||||
SshRemoteProcess::Ptr proc(new SshRemoteProcess(m_nextLocalChannelId++, m_sendFacility));
|
||||
insertChannel(proc->d, proc);
|
||||
return proc;
|
||||
}
|
||||
|
||||
Utils::SftpChannel::Ptr SshChannelManager::createSftpChannel()
|
||||
{
|
||||
SftpChannel::Ptr sftp(new SftpChannel(m_nextLocalChannelId++, m_sendFacility));
|
||||
|
||||
@@ -55,6 +55,7 @@ public:
|
||||
SshChannelManager(SshSendFacility &sendFacility, QObject *parent);
|
||||
|
||||
QSharedPointer<SshRemoteProcess> createRemoteProcess(const QByteArray &command);
|
||||
QSharedPointer<SshRemoteProcess> createRemoteShell();
|
||||
QSharedPointer<SftpChannel> createSftpChannel();
|
||||
void closeAllChannels();
|
||||
|
||||
|
||||
@@ -178,6 +178,12 @@ QSharedPointer<SshRemoteProcess> SshConnection::createRemoteProcess(const QByteA
|
||||
return d->createRemoteProcess(command);
|
||||
}
|
||||
|
||||
QSharedPointer<SshRemoteProcess> SshConnection::createRemoteShell()
|
||||
{
|
||||
QTC_ASSERT(state() == Connected, return QSharedPointer<SshRemoteProcess>());
|
||||
return d->createRemoteShell();
|
||||
}
|
||||
|
||||
QSharedPointer<SftpChannel> SshConnection::createSftpChannel()
|
||||
{
|
||||
QTC_ASSERT(state() == Connected, return QSharedPointer<SftpChannel>());
|
||||
@@ -678,6 +684,11 @@ QSharedPointer<SshRemoteProcess> SshConnectionPrivate::createRemoteProcess(const
|
||||
return m_channelManager->createRemoteProcess(command);
|
||||
}
|
||||
|
||||
QSharedPointer<SshRemoteProcess> SshConnectionPrivate::createRemoteShell()
|
||||
{
|
||||
return m_channelManager->createRemoteShell();
|
||||
}
|
||||
|
||||
QSharedPointer<SftpChannel> SshConnectionPrivate::createSftpChannel()
|
||||
{
|
||||
return m_channelManager->createSftpChannel();
|
||||
|
||||
@@ -89,6 +89,7 @@ public:
|
||||
~SshConnection();
|
||||
|
||||
QSharedPointer<SshRemoteProcess> createRemoteProcess(const QByteArray &command);
|
||||
QSharedPointer<SshRemoteProcess> createRemoteShell();
|
||||
QSharedPointer<SftpChannel> createSftpChannel();
|
||||
|
||||
signals:
|
||||
|
||||
@@ -90,6 +90,7 @@ public:
|
||||
void closeConnection(SshErrorCode sshError, SshError userError,
|
||||
const QByteArray &serverErrorString, const QString &userErrorString);
|
||||
QSharedPointer<SshRemoteProcess> createRemoteProcess(const QByteArray &command);
|
||||
QSharedPointer<SshRemoteProcess> createRemoteShell();
|
||||
QSharedPointer<SftpChannel> createSftpChannel();
|
||||
SshStateInternal state() const { return m_state; }
|
||||
SshError error() const { return m_error; }
|
||||
|
||||
@@ -179,6 +179,12 @@ void SshOutgoingPacket::generateExecPacket(quint32 remoteChannel,
|
||||
.appendBool(true).appendString(command).finalize();
|
||||
}
|
||||
|
||||
void SshOutgoingPacket::generateShellPacket(quint32 remoteChannel)
|
||||
{
|
||||
init(SSH_MSG_CHANNEL_REQUEST).appendInt(remoteChannel).appendString("shell")
|
||||
.appendBool(true).finalize();
|
||||
}
|
||||
|
||||
void SshOutgoingPacket::generateSftpPacket(quint32 remoteChannel)
|
||||
{
|
||||
init(SSH_MSG_CHANNEL_REQUEST).appendInt(remoteChannel)
|
||||
|
||||
@@ -69,6 +69,7 @@ public:
|
||||
void generatePtyRequestPacket(quint32 remoteChannel,
|
||||
const SshPseudoTerminal &terminal);
|
||||
void generateExecPacket(quint32 remoteChannel, const QByteArray &command);
|
||||
void generateShellPacket(quint32 remoteChannel);
|
||||
void generateSftpPacket(quint32 remoteChannel);
|
||||
void generateWindowAdjustPacket(quint32 remoteChannel, quint32 bytesToAdd);
|
||||
void generateChannelDataPacket(quint32 remoteChannel,
|
||||
|
||||
@@ -82,14 +82,13 @@ SshRemoteProcess::SshRemoteProcess(const QByteArray &command, quint32 channelId,
|
||||
Internal::SshSendFacility &sendFacility)
|
||||
: d(new Internal::SshRemoteProcessPrivate(command, channelId, sendFacility, this))
|
||||
{
|
||||
connect(d, SIGNAL(started()), this, SIGNAL(started()),
|
||||
Qt::QueuedConnection);
|
||||
connect(d, SIGNAL(outputAvailable(QByteArray)), this,
|
||||
SIGNAL(outputAvailable(QByteArray)), Qt::QueuedConnection);
|
||||
connect(d, SIGNAL(errorOutputAvailable(QByteArray)), this,
|
||||
SIGNAL(errorOutputAvailable(QByteArray)), Qt::QueuedConnection);
|
||||
connect(d, SIGNAL(closed(int)), this, SIGNAL(closed(int)),
|
||||
Qt::QueuedConnection);
|
||||
init();
|
||||
}
|
||||
|
||||
SshRemoteProcess::SshRemoteProcess(quint32 channelId, Internal::SshSendFacility &sendFacility)
|
||||
: d(new Internal::SshRemoteProcessPrivate(channelId, sendFacility, this))
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
SshRemoteProcess::~SshRemoteProcess()
|
||||
@@ -100,6 +99,18 @@ SshRemoteProcess::~SshRemoteProcess()
|
||||
delete d;
|
||||
}
|
||||
|
||||
void SshRemoteProcess::init()
|
||||
{
|
||||
connect(d, SIGNAL(started()), this, SIGNAL(started()),
|
||||
Qt::QueuedConnection);
|
||||
connect(d, SIGNAL(outputAvailable(QByteArray)), this,
|
||||
SIGNAL(outputAvailable(QByteArray)), Qt::QueuedConnection);
|
||||
connect(d, SIGNAL(errorOutputAvailable(QByteArray)), this,
|
||||
SIGNAL(errorOutputAvailable(QByteArray)), Qt::QueuedConnection);
|
||||
connect(d, SIGNAL(closed(int)), this, SIGNAL(closed(int)),
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void SshRemoteProcess::addToEnvironment(const QByteArray &var, const QByteArray &value)
|
||||
{
|
||||
if (d->channelState() == Internal::SshRemoteProcessPrivate::Inactive)
|
||||
@@ -160,11 +171,31 @@ QByteArray SshRemoteProcess::exitSignal() const { return d->m_signal; }
|
||||
namespace Internal {
|
||||
|
||||
SshRemoteProcessPrivate::SshRemoteProcessPrivate(const QByteArray &command,
|
||||
quint32 channelId, SshSendFacility &sendFacility, SshRemoteProcess *proc)
|
||||
: AbstractSshChannel(channelId, sendFacility), m_procState(NotYetStarted),
|
||||
m_wasRunning(false), m_exitCode(0), m_command(command),
|
||||
m_useTerminal(false), m_proc(proc)
|
||||
quint32 channelId, SshSendFacility &sendFacility, SshRemoteProcess *proc)
|
||||
: AbstractSshChannel(channelId, sendFacility),
|
||||
m_command(command),
|
||||
m_isShell(false),
|
||||
m_useTerminal(false),
|
||||
m_proc(proc)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
SshRemoteProcessPrivate::SshRemoteProcessPrivate(quint32 channelId, SshSendFacility &sendFacility,
|
||||
SshRemoteProcess *proc)
|
||||
: AbstractSshChannel(channelId, sendFacility),
|
||||
m_isShell(true),
|
||||
m_useTerminal(true),
|
||||
m_proc(proc)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
void SshRemoteProcessPrivate::init()
|
||||
{
|
||||
m_procState = NotYetStarted;
|
||||
m_wasRunning = false;
|
||||
m_exitCode = 0;
|
||||
}
|
||||
|
||||
void SshRemoteProcessPrivate::setProcState(ProcessState newState)
|
||||
@@ -201,7 +232,10 @@ void SshRemoteProcessPrivate::handleOpenSuccessInternal()
|
||||
if (m_useTerminal)
|
||||
m_sendFacility.sendPtyRequestPacket(remoteChannel(), m_terminal);
|
||||
|
||||
m_sendFacility.sendExecPacket(remoteChannel(), m_command);
|
||||
if (m_isShell)
|
||||
m_sendFacility.sendShellPacket(remoteChannel());
|
||||
else
|
||||
m_sendFacility.sendExecPacket(remoteChannel(), m_command);
|
||||
setProcState(ExecRequested);
|
||||
m_timeoutTimer->start(ReplyTimeout);
|
||||
}
|
||||
|
||||
@@ -112,6 +112,9 @@ signals:
|
||||
private:
|
||||
SshRemoteProcess(const QByteArray &command, quint32 channelId,
|
||||
Internal::SshSendFacility &sendFacility);
|
||||
SshRemoteProcess(quint32 channelId, Internal::SshSendFacility &sendFacility);
|
||||
|
||||
void init();
|
||||
|
||||
Internal::SshRemoteProcessPrivate *d;
|
||||
};
|
||||
|
||||
@@ -69,6 +69,8 @@ signals:
|
||||
private:
|
||||
SshRemoteProcessPrivate(const QByteArray &command, quint32 channelId,
|
||||
SshSendFacility &sendFacility, SshRemoteProcess *proc);
|
||||
SshRemoteProcessPrivate(quint32 channelId, SshSendFacility &sendFacility,
|
||||
SshRemoteProcess *proc);
|
||||
|
||||
virtual void handleOpenSuccessInternal();
|
||||
virtual void handleOpenFailureInternal();
|
||||
@@ -78,6 +80,7 @@ private:
|
||||
virtual void handleExitStatus(const SshChannelExitStatus &exitStatus);
|
||||
virtual void handleExitSignal(const SshChannelExitSignal &signal);
|
||||
|
||||
void init();
|
||||
void setProcState(ProcessState newState);
|
||||
|
||||
ProcessState m_procState;
|
||||
@@ -86,6 +89,7 @@ private:
|
||||
int m_exitCode;
|
||||
|
||||
const QByteArray m_command;
|
||||
const bool m_isShell;
|
||||
|
||||
typedef QPair<QByteArray, QByteArray> EnvVar;
|
||||
QList<EnvVar> m_env;
|
||||
|
||||
@@ -173,6 +173,12 @@ void SshSendFacility::sendExecPacket(quint32 remoteChannel,
|
||||
sendPacket();
|
||||
}
|
||||
|
||||
void SshSendFacility::sendShellPacket(quint32 remoteChannel)
|
||||
{
|
||||
m_outgoingPacket.generateShellPacket(remoteChannel);
|
||||
sendPacket();
|
||||
}
|
||||
|
||||
void SshSendFacility::sendSftpPacket(quint32 remoteChannel)
|
||||
{
|
||||
m_outgoingPacket.generateSftpPacket(remoteChannel);
|
||||
|
||||
@@ -76,6 +76,7 @@ public:
|
||||
void sendEnvPacket(quint32 remoteChannel, const QByteArray &var,
|
||||
const QByteArray &value);
|
||||
void sendExecPacket(quint32 remoteChannel, const QByteArray &command);
|
||||
void sendShellPacket(quint32 remoteChannel);
|
||||
void sendSftpPacket(quint32 remoteChannel);
|
||||
void sendWindowAdjustPacket(quint32 remoteChannel, quint32 bytesToAdd);
|
||||
void sendChannelDataPacket(quint32 remoteChannel, const QByteArray &data);
|
||||
|
||||
Reference in New Issue
Block a user