diff --git a/src/libs/utils/ssh/sshoutgoingpacket.cpp b/src/libs/utils/ssh/sshoutgoingpacket.cpp index 445aa75ae2a07f251cf5c86c4425305c00887232..7747c4332aaf92c5f3d80d6e933524f1224aa47c 100644 --- a/src/libs/utils/ssh/sshoutgoingpacket.cpp +++ b/src/libs/utils/ssh/sshoutgoingpacket.cpp @@ -151,7 +151,24 @@ void SshOutgoingPacket::generateEnvPacket(quint32 remoteChannel, const QByteArray &var, const QByteArray &value) { init(SSH_MSG_CHANNEL_REQUEST).appendInt(remoteChannel).appendString("env") - .appendBool(false).appendString(var).appendString(value); + .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, 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/sshpseudoterminal.h b/src/libs/utils/ssh/sshpseudoterminal.h new file mode 100644 index 0000000000000000000000000000000000000000..229095bcfff0c86e8700d277303069c240399736 --- /dev/null +++ b/src/libs/utils/ssh/sshpseudoterminal.h @@ -0,0 +1,118 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** No Commercial Usage +** +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ +#ifndef SSHPSEUDOTERMINAL_H +#define SSHPSEUDOTERMINAL_H + +#include <utils/utils_global.h> + +#include <QtCore/QByteArray> +#include <QtCore/QHash> + +namespace Utils { + +struct QTCREATOR_UTILS_EXPORT SshPseudoTerminal { + SshPseudoTerminal(const QByteArray &termType = "vt100", int rowCount = 24, + int columnCount = 80) + : termType(termType), rowCount(rowCount), columnCount(columnCount) {} + + QByteArray termType; + int rowCount; + int columnCount; + + enum Mode { + VINTR = 1, // Interrupt character. + VQUIT = 2, // The quit character (sends SIGQUIT signal on POSIX systems). + VERASE = 3, // Erase the character to left of the cursor. + VKILL = 4, // Kill the current input line. + VEOF = 5, // End-of-file character (sends EOF from the terminal). + VEOL = 6, // End-of-line character in addition to carriage return and/or linefeed. + VEOL2 = 7, // Additional end-of-line character. + VSTART = 8, // Continues paused output (normally control-Q). + VSTOP = 9, // Pauses output (normally control-S). + VSUSP = 10, // Suspends the current program. + VDSUSP = 11, // Another suspend character. + VREPRINT = 12, // Reprints the current input line. + VWERASE = 13, // Erases a word left of cursor. + VLNEXT = 14, // Enter the next character typed literally, even if it is a special character. + VFLUSH = 15, // Character to flush output. + VSWTCH = 16, // Switch to a different shell layer. + VSTATUS = 17, // Prints system status line (load, command, pid, etc). + VDISCARD = 18, // Toggles the flushing of terminal output. + + IGNPAR = 30, // The ignore parity flag. The parameter SHOULD be 0 if this flag is FALSE, and 1 if it is TRUE. + PARMRK = 31, // Mark parity and framing errors. + INPCK = 32, // Enable checking of parity errors. + ISTRIP = 33, // Strip 8th bit off characters. + INLCR = 34, // Map NL into CR on input. + IGNCR = 35, // Ignore CR on input. + ICRNL = 36, // Map CR to NL on input. + IUCLC = 37, // Translate uppercase characters to lowercase. + IXON = 38, // Enable output flow control. + IXANY = 39, // Any char will restart after stop. + IXOFF = 40, // Enable input flow control. + IMAXBEL = 41, // Ring bell on input queue full. + ISIG = 50, // Enable signals INTR, QUIT, [D]SUSP. + ICANON = 51, // Canonicalize input lines. + XCASE = 52, // Enable input and output of uppercase characters by preceding their lowercase equivalents with "\". + ECHO = 53, // Enable echoing. + ECHOE = 54, // Visually erase chars. + ECHOK = 55, // Kill character discards current line. + ECHONL = 56, // Echo NL even if ECHO is off. + NOFLSH = 57, // Don't flush after interrupt. + TOSTOP = 58, // Stop background jobs from output. + IEXTEN = 59, // Enable extensions. + ECHOCTL = 60, // Echo control characters as ^(Char). + ECHOKE = 61, // Visual erase for line kill. + PENDIN = 62, // Retype pending input. + OPOST = 70, // Enable output processing. + OLCUC = 71, // Convert lowercase to uppercase. + ONLCR = 72, // Map NL to CR-NL. + OCRNL = 73, // Translate carriage return to newline (output). + ONOCR = 74, // Translate newline to carriage return-newline (output). + ONLRET = 75, // Newline performs a carriage return (output). + CS7 = 90, // 7 bit mode. + CS8 = 91, // 8 bit mode. + PARENB = 92, // Parity enable. + PARODD = 93, // Odd parity, else even. + + TTY_OP_ISPEED = 128, // Specifies the input baud rate in bits per second. + TTY_OP_OSPEED = 129 // Specifies the output baud rate in bits per second. + }; + + typedef QHash<Mode, quint32> ModeMap; + ModeMap modes; +}; + +} // namespace Utils + +#endif // SSHPSEUDOTERMINAL_H 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 \ diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemodebugsupport.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemodebugsupport.cpp index 0a0c809645968ec556601c182bb5269ed7c95382..b1fd13077a92cd187d4cec27102c038895d25cd2 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemodebugsupport.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemodebugsupport.cpp @@ -338,7 +338,7 @@ void MaemoDebugSupport::handleRemoteErrorOutput(const QByteArray &output) void MaemoDebugSupport::handleProgressReport(const QString &progressOutput) { - showMessage(progressOutput, AppStuff); + showMessage(progressOutput + QLatin1Char('\n'), AppStuff); } void MaemoDebugSupport::handleAdapterSetupFailed(const QString &error) diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemoruncontrol.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemoruncontrol.cpp index e5ffd635e77685bf21d0fd0bd3d118efc0d884c8..4474d5a0e5206d2521cb880e708645cae722735a 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemoruncontrol.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemoruncontrol.cpp @@ -98,7 +98,7 @@ void MaemoRunControl::handleSshError(const QString &error) void MaemoRunControl::startExecution() { - appendMessage(tr("Starting remote process ..."), NormalMessageFormat); + appendMessage(tr("Starting remote process ...\n"), NormalMessageFormat); m_runner->startExecution(QString::fromLocal8Bit("%1 %2 %3 %4") .arg(MaemoGlobal::remoteCommandPrefix(m_runner->remoteExecutable())) .arg(MaemoGlobal::remoteEnvironment(m_runner->userEnvChanges())) @@ -109,7 +109,7 @@ void MaemoRunControl::startExecution() void MaemoRunControl::handleRemoteProcessFinished(qint64 exitCode) { if (exitCode != MaemoSshRunner::InvalidExitCode) { - appendMessage(tr("Finished running remote process. Exit code was %1.") + appendMessage(tr("Finished running remote process. Exit code was %1.\n") .arg(exitCode), NormalMessageFormat); } setFinished(); @@ -127,7 +127,7 @@ void MaemoRunControl::handleRemoteErrorOutput(const QByteArray &output) void MaemoRunControl::handleProgressReport(const QString &progressString) { - appendMessage(progressString, NormalMessageFormat); + appendMessage(progressString + QLatin1Char('\n'), NormalMessageFormat); } void MaemoRunControl::handleMountDebugOutput(const QString &output)