diff --git a/src/libs/utils/ssh/sshoutgoingpacket.cpp b/src/libs/utils/ssh/sshoutgoingpacket.cpp index 52fc32d9b4bce4cd385233ab67236cd02b415265..7747c4332aaf92c5f3d80d6e933524f1224aa47c 100644 --- a/src/libs/utils/ssh/sshoutgoingpacket.cpp +++ b/src/libs/utils/ssh/sshoutgoingpacket.cpp @@ -154,6 +154,23 @@ void SshOutgoingPacket::generateEnvPacket(quint32 remoteChannel, .appendBool(false).appendString(var).appendString(value).finalize(); } +void SshOutgoingPacket::generatePtyRequestPacket(quint32 remoteChannel, + const SshPseudoTerminal &terminal) +{ + init(SSH_MSG_CHANNEL_REQUEST).appendInt(remoteChannel) + .appendString("pty-req").appendBool(false) + .appendString(terminal.termType).appendInt(terminal.columnCount) + .appendInt(terminal.rowCount); + QByteArray modeString; + for (SshPseudoTerminal::ModeMap::ConstIterator it = terminal.modes.constBegin(); + it != terminal.modes.constEnd(); ++it) { + modeString += encodeInt(static_cast<quint8>(it.key())); + modeString += encodeInt(it.value()); + } + modeString += encodeInt(static_cast<quint8>(0)); // TTY_OP_END + appendString(modeString).finalize(); +} + void SshOutgoingPacket::generateExecPacket(quint32 remoteChannel, const QByteArray &command) { diff --git a/src/libs/utils/ssh/sshoutgoingpacket_p.h b/src/libs/utils/ssh/sshoutgoingpacket_p.h index 22adf6d2e7c3300eacdcfc0262ec2ce086d53e13..e27c89e51857198dac122dc9f691839c93d2da75 100644 --- a/src/libs/utils/ssh/sshoutgoingpacket_p.h +++ b/src/libs/utils/ssh/sshoutgoingpacket_p.h @@ -36,6 +36,8 @@ #include "sshpacket_p.h" +#include "sshpseudoterminal.h" + namespace Utils { namespace Internal { @@ -65,6 +67,8 @@ public: quint32 maxPacketSize); void generateEnvPacket(quint32 remoteChannel, const QByteArray &var, const QByteArray &value); + void generatePtyRequestPacket(quint32 remoteChannel, + const SshPseudoTerminal &terminal); void generateExecPacket(quint32 remoteChannel, const QByteArray &command); void generateSftpPacket(quint32 remoteChannel); void generateWindowAdjustPacket(quint32 remoteChannel, quint32 bytesToAdd); diff --git a/src/libs/utils/ssh/sshremoteprocess.cpp b/src/libs/utils/ssh/sshremoteprocess.cpp index 8f0620b2b1694016377fca9b4e3c8585a14fd67b..91626dd347682b20384ffe88ecee5cf703620547 100644 --- a/src/libs/utils/ssh/sshremoteprocess.cpp +++ b/src/libs/utils/ssh/sshremoteprocess.cpp @@ -39,6 +39,8 @@ #include <botan/exceptn.h> +#include <utils/qtcassert.h> + #include <QtCore/QTimer> /*! @@ -57,8 +59,8 @@ Therefore, the only sensible use case for calling closeChannel() is to get rid of an SshRemoteProces object before the process is actually started. - Note that the process does not have a terminal, so you can't use it - for applications that require one. + If the process needs a pseudo terminal, you can request one + via requestTerminal() before calling start(). */ namespace Utils { @@ -105,6 +107,13 @@ void SshRemoteProcess::addToEnvironment(const QByteArray &var, const QByteArray d->m_env << qMakePair(var, value); // Cached locally and sent on start() } +void SshRemoteProcess::requestTerminal(const SshPseudoTerminal &terminal) +{ + QTC_ASSERT(d->channelState() == Internal::SshRemoteProcessPrivate::Inactive, return); + d->m_useTerminal = true; + d->m_terminal = terminal; +} + void SshRemoteProcess::start() { if (d->channelState() == Internal::SshRemoteProcessPrivate::Inactive) { @@ -154,7 +163,8 @@ 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_proc(proc) + m_wasRunning(false), m_exitCode(0), m_command(command), + m_useTerminal(false), m_proc(proc) { } @@ -189,6 +199,10 @@ void SshRemoteProcessPrivate::handleOpenSuccessInternal() envVar.second); } + if (m_useTerminal) { + // TODO: Encode m_terminal + } + m_sendFacility.sendExecPacket(remoteChannel(), m_command); setProcState(ExecRequested); m_timeoutTimer->start(ReplyTimeout); diff --git a/src/libs/utils/ssh/sshremoteprocess.h b/src/libs/utils/ssh/sshremoteprocess.h index df81336b07ec985b39a7a4b937ab4a86910044f9..31ece89e63d091a77b6de2d7a5a3dcd64082900b 100644 --- a/src/libs/utils/ssh/sshremoteprocess.h +++ b/src/libs/utils/ssh/sshremoteprocess.h @@ -44,6 +44,7 @@ class QByteArray; QT_END_NAMESPACE namespace Utils { +class SshPseudoTerminal; namespace Internal { class SshChannelManager; class SshRemoteProcessPrivate; @@ -84,6 +85,7 @@ public: */ void addToEnvironment(const QByteArray &var, const QByteArray &value); + void requestTerminal(const SshPseudoTerminal &terminal); void start(); void closeChannel(); diff --git a/src/libs/utils/ssh/sshremoteprocess_p.h b/src/libs/utils/ssh/sshremoteprocess_p.h index d667bde2f04b1a156ac27f1922a574006fb1fb2e..0c87e6841195dba80058791d8977b59db5d93400 100644 --- a/src/libs/utils/ssh/sshremoteprocess_p.h +++ b/src/libs/utils/ssh/sshremoteprocess_p.h @@ -34,6 +34,8 @@ #ifndef SSHREMOTEPROCESS_P_H #define SSHREMOTEPROCESS_P_H +#include "sshpseudoterminal.h" + #include "sshchannel_p.h" #include <QtCore/QList> @@ -88,6 +90,8 @@ private: typedef QPair<QByteArray, QByteArray> EnvVar; QList<EnvVar> m_env; + bool m_useTerminal; + SshPseudoTerminal m_terminal; SshRemoteProcess *m_proc; }; diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index 420e299e39b2ca39caa3f317e88fc700ccf319bc..4d4b3d3f956ee8eacf98cd5a4750fa70aa978d01 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -172,6 +172,7 @@ HEADERS += $$PWD/environment.h \ $$PWD/ssh/sftpchannel_p.h \ $$PWD/ssh/sshremoteprocessrunner.h \ $$PWD/ssh/sshconnectionmanager.h \ + $$PWD/ssh/sshpseudoterminal.h \ $$PWD/statuslabel.h FORMS += $$PWD/filewizardpage.ui \