forked from qt-creator/qt-creator
Get rid of SshRemoteProcess
It's being replaced by QtcProcess with path on device. Change-Id: I29eb038d1b17151683f86855eb547e47f7f7dea5 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -13,6 +13,5 @@ add_qtc_library(QtcSsh
|
|||||||
sshconnectionmanager.cpp sshconnectionmanager.h
|
sshconnectionmanager.cpp sshconnectionmanager.h
|
||||||
sshkeycreationdialog.cpp sshkeycreationdialog.h sshkeycreationdialog.ui
|
sshkeycreationdialog.cpp sshkeycreationdialog.h sshkeycreationdialog.ui
|
||||||
sshlogging.cpp sshlogging_p.h
|
sshlogging.cpp sshlogging_p.h
|
||||||
sshremoteprocess.cpp sshremoteprocess.h
|
|
||||||
sshsettings.cpp sshsettings.h
|
sshsettings.cpp sshsettings.h
|
||||||
)
|
)
|
||||||
|
@@ -31,8 +31,6 @@ Project {
|
|||||||
"sshkeycreationdialog.ui",
|
"sshkeycreationdialog.ui",
|
||||||
"sshlogging.cpp",
|
"sshlogging.cpp",
|
||||||
"sshlogging_p.h",
|
"sshlogging_p.h",
|
||||||
"sshremoteprocess.cpp",
|
|
||||||
"sshremoteprocess.h",
|
|
||||||
"sshsettings.cpp",
|
"sshsettings.cpp",
|
||||||
"sshsettings.h",
|
"sshsettings.h",
|
||||||
]
|
]
|
||||||
|
@@ -27,7 +27,6 @@
|
|||||||
|
|
||||||
#include "sftptransfer.h"
|
#include "sftptransfer.h"
|
||||||
#include "sshlogging_p.h"
|
#include "sshlogging_p.h"
|
||||||
#include "sshremoteprocess.h"
|
|
||||||
#include "sshsettings.h"
|
#include "sshsettings.h"
|
||||||
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
@@ -286,18 +285,6 @@ SshConnection::~SshConnection()
|
|||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
SshRemoteProcessPtr SshConnection::createRemoteProcess(const QString &command)
|
|
||||||
{
|
|
||||||
QTC_ASSERT(state() == Connected, return SshRemoteProcessPtr());
|
|
||||||
return SshRemoteProcessPtr(new SshRemoteProcess(command,
|
|
||||||
d->connectionArgs(SshSettings::sshFilePath())));
|
|
||||||
}
|
|
||||||
|
|
||||||
SshRemoteProcessPtr SshConnection::createRemoteShell()
|
|
||||||
{
|
|
||||||
return createRemoteProcess({});
|
|
||||||
}
|
|
||||||
|
|
||||||
SftpTransferPtr SshConnection::createUpload(const FilesToTransfer &files,
|
SftpTransferPtr SshConnection::createUpload(const FilesToTransfer &files,
|
||||||
FileTransferErrorHandling errorHandlingMode)
|
FileTransferErrorHandling errorHandlingMode)
|
||||||
{
|
{
|
||||||
|
@@ -41,7 +41,6 @@
|
|||||||
namespace Utils { class QtcProcess; }
|
namespace Utils { class QtcProcess; }
|
||||||
|
|
||||||
namespace QSsh {
|
namespace QSsh {
|
||||||
class SshRemoteProcess;
|
|
||||||
|
|
||||||
enum SshHostKeyCheckingMode {
|
enum SshHostKeyCheckingMode {
|
||||||
SshHostKeyCheckingNone,
|
SshHostKeyCheckingNone,
|
||||||
@@ -82,8 +81,6 @@ public:
|
|||||||
QSSH_EXPORT bool operator==(const SshConnectionParameters &p1, const SshConnectionParameters &p2);
|
QSSH_EXPORT bool operator==(const SshConnectionParameters &p1, const SshConnectionParameters &p2);
|
||||||
QSSH_EXPORT bool operator!=(const SshConnectionParameters &p1, const SshConnectionParameters &p2);
|
QSSH_EXPORT bool operator!=(const SshConnectionParameters &p1, const SshConnectionParameters &p2);
|
||||||
|
|
||||||
using SshRemoteProcessPtr = std::unique_ptr<SshRemoteProcess>;
|
|
||||||
|
|
||||||
class QSSH_EXPORT SshConnection : public QObject
|
class QSSH_EXPORT SshConnection : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -102,8 +99,6 @@ public:
|
|||||||
bool sharingEnabled() const;
|
bool sharingEnabled() const;
|
||||||
~SshConnection();
|
~SshConnection();
|
||||||
|
|
||||||
SshRemoteProcessPtr createRemoteProcess(const QString &command);
|
|
||||||
SshRemoteProcessPtr createRemoteShell();
|
|
||||||
SftpTransferPtr createUpload(const FilesToTransfer &files,
|
SftpTransferPtr createUpload(const FilesToTransfer &files,
|
||||||
FileTransferErrorHandling errorHandlingMode);
|
FileTransferErrorHandling errorHandlingMode);
|
||||||
SftpTransferPtr createDownload(const FilesToTransfer &files,
|
SftpTransferPtr createDownload(const FilesToTransfer &files,
|
||||||
|
@@ -1,116 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and The Qt Company. For licensing terms
|
|
||||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
||||||
** information use the contact form at https://www.qt.io/contact-us.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU
|
|
||||||
** General Public License version 3 as published by the Free Software
|
|
||||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
||||||
** included in the packaging of this file. Please review the following
|
|
||||||
** information to ensure the GNU General Public License requirements will
|
|
||||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "sshremoteprocess.h"
|
|
||||||
|
|
||||||
#include "sshconnection.h"
|
|
||||||
#include "sshlogging_p.h"
|
|
||||||
#include "sshsettings.h"
|
|
||||||
|
|
||||||
#include <utils/commandline.h>
|
|
||||||
#include <utils/processinterface.h>
|
|
||||||
#include <utils/qtcassert.h>
|
|
||||||
|
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\class QSsh::SshRemoteProcess
|
|
||||||
|
|
||||||
\brief The SshRemoteProcess class implements an SSH channel for running a
|
|
||||||
remote process.
|
|
||||||
|
|
||||||
Objects are created via SshConnection::createRemoteProcess.
|
|
||||||
The process is started via the start() member function.
|
|
||||||
If the process needs a pseudo terminal, you can request one
|
|
||||||
via requestTerminal() before calling start().
|
|
||||||
*/
|
|
||||||
|
|
||||||
using namespace QSsh::Internal;
|
|
||||||
using namespace Utils;
|
|
||||||
|
|
||||||
namespace QSsh {
|
|
||||||
|
|
||||||
SshRemoteProcess::SshRemoteProcess(const QString &command, const QStringList &connectionArgs)
|
|
||||||
: QtcProcess()
|
|
||||||
{
|
|
||||||
SshConnectionParameters::setupSshEnvironment(this);
|
|
||||||
m_remoteCommand = command;
|
|
||||||
m_connectionArgs = connectionArgs;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SshRemoteProcess::emitFinished()
|
|
||||||
{
|
|
||||||
if (exitStatus() == QProcess::CrashExit)
|
|
||||||
m_errorString = tr("The ssh process crashed: %1").arg(errorString());
|
|
||||||
QtcProcess::emitFinished();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SshRemoteProcess::startImpl()
|
|
||||||
{
|
|
||||||
QTC_ASSERT(!isRunning(), return);
|
|
||||||
m_errorString.clear();
|
|
||||||
const CommandLine cmd = fullLocalCommandLine();
|
|
||||||
if (!m_displayName.isEmpty()) {
|
|
||||||
Environment env = environment();
|
|
||||||
env.set("DISPLAY", m_displayName);
|
|
||||||
setEnvironment(env);
|
|
||||||
}
|
|
||||||
qCDebug(sshLog) << "starting remote process:" << cmd.toUserOutput();
|
|
||||||
setCommand(cmd);
|
|
||||||
QtcProcess::startImpl();
|
|
||||||
}
|
|
||||||
|
|
||||||
ProcessResultData SshRemoteProcess::resultData() const
|
|
||||||
{
|
|
||||||
ProcessResultData result = QtcProcess::resultData();
|
|
||||||
if (!m_errorString.isEmpty())
|
|
||||||
result.m_errorString = m_errorString;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SshRemoteProcess::requestX11Forwarding(const QString &displayName)
|
|
||||||
{
|
|
||||||
m_displayName = displayName;
|
|
||||||
}
|
|
||||||
|
|
||||||
CommandLine SshRemoteProcess::fullLocalCommandLine(bool inTerminal) const
|
|
||||||
{
|
|
||||||
CommandLine cmd {SshSettings::sshFilePath()};
|
|
||||||
|
|
||||||
if (!m_displayName.isEmpty())
|
|
||||||
cmd.addArg("-X");
|
|
||||||
if (inTerminal)
|
|
||||||
cmd.addArg("-tt");
|
|
||||||
|
|
||||||
cmd.addArg("-q");
|
|
||||||
cmd.addArgs(m_connectionArgs);
|
|
||||||
|
|
||||||
if (!m_remoteCommand.isEmpty())
|
|
||||||
cmd.addArg(m_remoteCommand);
|
|
||||||
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace QSsh
|
|
@@ -1,59 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and The Qt Company. For licensing terms
|
|
||||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
||||||
** information use the contact form at https://www.qt.io/contact-us.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU
|
|
||||||
** General Public License version 3 as published by the Free Software
|
|
||||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
||||||
** included in the packaging of this file. Please review the following
|
|
||||||
** information to ensure the GNU General Public License requirements will
|
|
||||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "ssh_global.h"
|
|
||||||
|
|
||||||
#include <utils/qtcprocess.h>
|
|
||||||
|
|
||||||
namespace Utils { class CommandLine; }
|
|
||||||
|
|
||||||
namespace QSsh {
|
|
||||||
|
|
||||||
class QSSH_EXPORT SshRemoteProcess : public Utils::QtcProcess
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
SshRemoteProcess(const QString &command, const QStringList &connectionArgs);
|
|
||||||
|
|
||||||
void requestX11Forwarding(const QString &displayName);
|
|
||||||
void startImpl() override;
|
|
||||||
Utils::ProcessResultData resultData() const override;
|
|
||||||
|
|
||||||
Utils::CommandLine fullLocalCommandLine(bool inTerminal = false) const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void emitFinished() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString m_remoteCommand;
|
|
||||||
QStringList m_connectionArgs;
|
|
||||||
QString m_displayName;
|
|
||||||
QString m_errorString;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace QSsh
|
|
@@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
#include <ssh/sftptransfer.h>
|
#include <ssh/sftptransfer.h>
|
||||||
#include <ssh/sshconnection.h>
|
#include <ssh/sshconnection.h>
|
||||||
#include <ssh/sshremoteprocess.h>
|
|
||||||
#include <ssh/sshsettings.h>
|
#include <ssh/sshsettings.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
@@ -59,7 +58,6 @@ private slots:
|
|||||||
void errorHandling_data();
|
void errorHandling_data();
|
||||||
void errorHandling();
|
void errorHandling();
|
||||||
void pristineConnectionObject();
|
void pristineConnectionObject();
|
||||||
void remoteProcessChannels();
|
|
||||||
void remoteProcessInput();
|
void remoteProcessInput();
|
||||||
void sftp();
|
void sftp();
|
||||||
|
|
||||||
@@ -145,46 +143,6 @@ void tst_Ssh::pristineConnectionObject()
|
|||||||
QRegularExpression assertToIgnore(
|
QRegularExpression assertToIgnore(
|
||||||
"SOFT ASSERT: \"state\\(\\) == Connected\" in file .*[/\\\\]sshconnection.cpp, line \\d*");
|
"SOFT ASSERT: \"state\\(\\) == Connected\" in file .*[/\\\\]sshconnection.cpp, line \\d*");
|
||||||
QTest::ignoreMessage(QtDebugMsg, assertToIgnore);
|
QTest::ignoreMessage(QtDebugMsg, assertToIgnore);
|
||||||
QVERIFY(!connection.createRemoteProcess(""));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_Ssh::remoteProcessChannels()
|
|
||||||
{
|
|
||||||
const SshConnectionParameters params = SshTest::getParameters();
|
|
||||||
if (!SshTest::checkParameters(params))
|
|
||||||
QSKIP("Insufficient setup - set QTC_SSH_TEST_* variables.");
|
|
||||||
SshConnection connection(params);
|
|
||||||
QVERIFY(waitForConnection(connection));
|
|
||||||
|
|
||||||
static const QByteArray testString("ChannelTest");
|
|
||||||
QByteArray remoteStdout;
|
|
||||||
QByteArray remoteStderr;
|
|
||||||
QByteArray remoteData;
|
|
||||||
SshRemoteProcessPtr echoProcess
|
|
||||||
= connection.createRemoteProcess("printf " + QString::fromUtf8(testString) + " >&2");
|
|
||||||
QEventLoop loop;
|
|
||||||
connect(echoProcess.get(), &QtcProcess::done, &loop, &QEventLoop::quit);
|
|
||||||
connect(echoProcess.get(), &QtcProcess::readyReadStandardError,
|
|
||||||
[&remoteData, p = echoProcess.get()] { remoteData += p->readAllStandardError(); });
|
|
||||||
connect(echoProcess.get(), &QtcProcess::readyReadStandardOutput,
|
|
||||||
[&remoteStdout, p = echoProcess.get()] { remoteStdout += p->readAllStandardOutput(); });
|
|
||||||
connect(echoProcess.get(), &QtcProcess::readyReadStandardError,
|
|
||||||
[&remoteStderr] { remoteStderr = testString; });
|
|
||||||
echoProcess->start();
|
|
||||||
QTimer timer;
|
|
||||||
QObject::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
|
|
||||||
timer.setSingleShot(true);
|
|
||||||
timer.setInterval((params.timeout + 5) * 1000);
|
|
||||||
timer.start();
|
|
||||||
loop.exec();
|
|
||||||
QVERIFY(timer.isActive());
|
|
||||||
timer.stop();
|
|
||||||
QVERIFY(!echoProcess->isRunning());
|
|
||||||
QCOMPARE(echoProcess->exitStatus(), QProcess::NormalExit);
|
|
||||||
QCOMPARE(echoProcess->exitCode(), 0);
|
|
||||||
QVERIFY(remoteStdout.isEmpty());
|
|
||||||
QCOMPARE(remoteData, testString);
|
|
||||||
QCOMPARE(remoteData, remoteStderr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_Ssh::remoteProcessInput()
|
void tst_Ssh::remoteProcessInput()
|
||||||
|
@@ -16,5 +16,4 @@ add_subdirectory(proparser)
|
|||||||
# add_subdirectory(qt4projectmanager)
|
# add_subdirectory(qt4projectmanager)
|
||||||
# add_subdirectory(search)
|
# add_subdirectory(search)
|
||||||
add_subdirectory(shootout)
|
add_subdirectory(shootout)
|
||||||
add_subdirectory(ssh)
|
|
||||||
add_subdirectory(widgets)
|
add_subdirectory(widgets)
|
||||||
|
@@ -13,7 +13,6 @@ Project {
|
|||||||
"process/process.qbs",
|
"process/process.qbs",
|
||||||
"proparser/testreader.qbs",
|
"proparser/testreader.qbs",
|
||||||
"shootout/shootout.qbs",
|
"shootout/shootout.qbs",
|
||||||
"ssh/shell/shell.qbs",
|
|
||||||
"widgets/widgets.qbs",
|
"widgets/widgets.qbs",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@@ -1 +0,0 @@
|
|||||||
add_subdirectory(shell)
|
|
@@ -1,13 +0,0 @@
|
|||||||
file(RELATIVE_PATH RELATIVE_TEST_PATH "${PROJECT_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}")
|
|
||||||
file(RELATIVE_PATH TEST_RELATIVE_LIBEXEC_PATH "/${RELATIVE_TEST_PATH}" "/${IDE_LIBEXEC_PATH}")
|
|
||||||
|
|
||||||
add_qtc_test(tst_manual_shell
|
|
||||||
MANUALTEST
|
|
||||||
CONDITION UNIX
|
|
||||||
DEPENDS Utils QtcSsh Qt5::Network
|
|
||||||
DEFINES "TEST_RELATIVE_LIBEXEC_PATH=\"${TEST_RELATIVE_LIBEXEC_PATH}\""
|
|
||||||
SOURCES
|
|
||||||
argumentscollector.cpp argumentscollector.h
|
|
||||||
main.cpp
|
|
||||||
shell.cpp shell.h
|
|
||||||
)
|
|
@@ -1,135 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and The Qt Company. For licensing terms
|
|
||||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
||||||
** information use the contact form at https://www.qt.io/contact-us.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU
|
|
||||||
** General Public License version 3 as published by the Free Software
|
|
||||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
||||||
** included in the packaging of this file. Please review the following
|
|
||||||
** information to ensure the GNU General Public License requirements will
|
|
||||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "argumentscollector.h"
|
|
||||||
|
|
||||||
#include <QDir>
|
|
||||||
#include <QProcessEnvironment>
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
using namespace QSsh;
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
ArgumentsCollector::ArgumentsCollector(const QStringList &args)
|
|
||||||
: m_arguments(args)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
SshConnectionParameters ArgumentsCollector::collect(bool &success) const
|
|
||||||
{
|
|
||||||
SshConnectionParameters parameters;
|
|
||||||
try {
|
|
||||||
bool authTypeGiven = false;
|
|
||||||
bool portGiven = false;
|
|
||||||
bool timeoutGiven = false;
|
|
||||||
int pos;
|
|
||||||
int port = 22;
|
|
||||||
|
|
||||||
for (pos = 1; pos < m_arguments.count() - 1; ++pos) {
|
|
||||||
QString str;
|
|
||||||
if (checkAndSetStringArg(pos, str, "-h")) {
|
|
||||||
parameters.setHost(str);
|
|
||||||
} else if (checkAndSetStringArg(pos, str, "-u")) {
|
|
||||||
parameters.setUserName(str);
|
|
||||||
} else if (checkAndSetIntArg(pos, port, portGiven, "-p")
|
|
||||||
|| checkAndSetIntArg(pos, parameters.timeout, timeoutGiven, "-t")) {
|
|
||||||
continue;
|
|
||||||
} else if (checkAndSetStringArg(pos, str, "-k")) {
|
|
||||||
parameters.privateKeyFile = Utils::FilePath::fromString(str);
|
|
||||||
parameters.authenticationType
|
|
||||||
= SshConnectionParameters::AuthenticationTypeSpecificKey;
|
|
||||||
authTypeGiven = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(pos <= m_arguments.count());
|
|
||||||
|
|
||||||
if (!authTypeGiven)
|
|
||||||
parameters.authenticationType = SshConnectionParameters::AuthenticationTypeAll;
|
|
||||||
|
|
||||||
if (parameters.userName().isEmpty())
|
|
||||||
parameters.setUserName(QProcessEnvironment::systemEnvironment().value("USER"));
|
|
||||||
if (parameters.userName().isEmpty())
|
|
||||||
throw ArgumentErrorException(QLatin1String("No user name given."));
|
|
||||||
|
|
||||||
if (parameters.host().isEmpty())
|
|
||||||
throw ArgumentErrorException(QLatin1String("No host given."));
|
|
||||||
|
|
||||||
parameters.setPort(portGiven ? port : 22);
|
|
||||||
if (!timeoutGiven)
|
|
||||||
parameters.timeout = 30;
|
|
||||||
success = true;
|
|
||||||
} catch (ArgumentErrorException &ex) {
|
|
||||||
cerr << "Error: " << qPrintable(ex.error) << endl;
|
|
||||||
printUsage();
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
return parameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ArgumentsCollector::printUsage() const
|
|
||||||
{
|
|
||||||
cerr << "Usage: " << qPrintable(m_arguments.first())
|
|
||||||
<< " -h <host> [ -u <user> ] "
|
|
||||||
<< "[ -k <private key file> ] [ -p <port> ] "
|
|
||||||
<< "[ -t <timeout> ] [ -no-proxy ]" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ArgumentsCollector::checkAndSetStringArg(int &pos, QString &arg, const char *opt) const
|
|
||||||
{
|
|
||||||
if (m_arguments.at(pos) == QLatin1String(opt)) {
|
|
||||||
if (!arg.isEmpty()) {
|
|
||||||
throw ArgumentErrorException(QLatin1String("option ") + QLatin1String(opt)
|
|
||||||
+ QLatin1String(" was given twice."));
|
|
||||||
}
|
|
||||||
arg = m_arguments.at(++pos);
|
|
||||||
if (arg.isEmpty() && QLatin1String(opt) != QLatin1String("-pwd"))
|
|
||||||
throw ArgumentErrorException(QLatin1String("empty argument not allowed here."));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ArgumentsCollector::checkAndSetIntArg(int &pos, int &val,
|
|
||||||
bool &alreadyGiven, const char *opt) const
|
|
||||||
{
|
|
||||||
if (m_arguments.at(pos) == QLatin1String(opt)) {
|
|
||||||
if (alreadyGiven) {
|
|
||||||
throw ArgumentErrorException(QLatin1String("option ") + QLatin1String(opt)
|
|
||||||
+ QLatin1String(" was given twice."));
|
|
||||||
}
|
|
||||||
bool isNumber;
|
|
||||||
val = m_arguments.at(++pos).toInt(&isNumber);
|
|
||||||
if (!isNumber) {
|
|
||||||
throw ArgumentErrorException(QLatin1String("option ") + QLatin1String(opt)
|
|
||||||
+ QLatin1String(" needs integer argument"));
|
|
||||||
}
|
|
||||||
alreadyGiven = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
@@ -1,50 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and The Qt Company. For licensing terms
|
|
||||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
||||||
** information use the contact form at https://www.qt.io/contact-us.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU
|
|
||||||
** General Public License version 3 as published by the Free Software
|
|
||||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
||||||
** included in the packaging of this file. Please review the following
|
|
||||||
** information to ensure the GNU General Public License requirements will
|
|
||||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <ssh/sshconnection.h>
|
|
||||||
|
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
class ArgumentsCollector
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ArgumentsCollector(const QStringList &args);
|
|
||||||
QSsh::SshConnectionParameters collect(bool &success) const;
|
|
||||||
private:
|
|
||||||
struct ArgumentErrorException
|
|
||||||
{
|
|
||||||
ArgumentErrorException(const QString &error) : error(error) {}
|
|
||||||
const QString error;
|
|
||||||
};
|
|
||||||
|
|
||||||
void printUsage() const;
|
|
||||||
bool checkAndSetStringArg(int &pos, QString &arg, const char *opt) const;
|
|
||||||
bool checkAndSetIntArg(int &pos, int &val, bool &alreadyGiven,
|
|
||||||
const char *opt) const;
|
|
||||||
|
|
||||||
const QStringList m_arguments;
|
|
||||||
};
|
|
@@ -1,56 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and The Qt Company. For licensing terms
|
|
||||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
||||||
** information use the contact form at https://www.qt.io/contact-us.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU
|
|
||||||
** General Public License version 3 as published by the Free Software
|
|
||||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
||||||
** included in the packaging of this file. Please review the following
|
|
||||||
** information to ensure the GNU General Public License requirements will
|
|
||||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "argumentscollector.h"
|
|
||||||
#include "shell.h"
|
|
||||||
|
|
||||||
#include <ssh/sshconnection.h>
|
|
||||||
#include <utils/launcherinterface.h>
|
|
||||||
#include <utils/temporarydirectory.h>
|
|
||||||
|
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QObject>
|
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
QCoreApplication app(argc, argv);
|
|
||||||
Utils::LauncherInterface::setPathToLauncher(qApp->applicationDirPath() + '/'
|
|
||||||
+ QLatin1String(TEST_RELATIVE_LIBEXEC_PATH));
|
|
||||||
bool parseSuccess;
|
|
||||||
const QSsh::SshConnectionParameters ¶meters
|
|
||||||
= ArgumentsCollector(app.arguments()).collect(parseSuccess);
|
|
||||||
if (!parseSuccess)
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
Utils::TemporaryDirectory::setMasterTemporaryDirectory(QDir::tempPath()
|
|
||||||
+ "/qtc-ssh-shelltest-XXXXXX");
|
|
||||||
Shell shell(parameters);
|
|
||||||
shell.run();
|
|
||||||
return app.exec();
|
|
||||||
}
|
|
@@ -1,111 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and The Qt Company. For licensing terms
|
|
||||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
||||||
** information use the contact form at https://www.qt.io/contact-us.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU
|
|
||||||
** General Public License version 3 as published by the Free Software
|
|
||||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
||||||
** included in the packaging of this file. Please review the following
|
|
||||||
** information to ensure the GNU General Public License requirements will
|
|
||||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "shell.h"
|
|
||||||
|
|
||||||
#include <ssh/sshremoteprocess.h>
|
|
||||||
|
|
||||||
#include <utils/qtcprocess.h>
|
|
||||||
|
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <QFile>
|
|
||||||
#include <QSocketNotifier>
|
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
using namespace QSsh;
|
|
||||||
using namespace Utils;
|
|
||||||
|
|
||||||
Shell::Shell(const SshConnectionParameters ¶meters, QObject *parent)
|
|
||||||
: QObject(parent),
|
|
||||||
m_connection(new SshConnection(parameters)),
|
|
||||||
m_stdin(new QFile(this))
|
|
||||||
{
|
|
||||||
connect(m_connection, &SshConnection::connected, this, &Shell::handleConnected);
|
|
||||||
connect(m_connection, &SshConnection::errorOccurred, this, &Shell::handleConnectionError);
|
|
||||||
}
|
|
||||||
|
|
||||||
Shell::~Shell()
|
|
||||||
{
|
|
||||||
delete m_connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Shell::run()
|
|
||||||
{
|
|
||||||
if (!m_stdin->open(stdin, QIODevice::ReadOnly | QIODevice::Unbuffered)) {
|
|
||||||
std::cerr << "Error: Cannot read from standard input." << std::endl;
|
|
||||||
QCoreApplication::exit(EXIT_FAILURE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_connection->connectToHost();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Shell::handleConnectionError()
|
|
||||||
{
|
|
||||||
std::cerr << "SSH connection error: " << qPrintable(m_connection->errorString()) << std::endl;
|
|
||||||
QCoreApplication::exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Shell::handleConnected()
|
|
||||||
{
|
|
||||||
m_shell = m_connection->createRemoteShell();
|
|
||||||
connect(m_shell.get(), &QtcProcess::started, this, &Shell::handleShellStarted);
|
|
||||||
connect(m_shell.get(), &QtcProcess::readyReadStandardOutput,
|
|
||||||
this, &Shell::handleRemoteStdout);
|
|
||||||
connect(m_shell.get(), &QtcProcess::readyReadStandardError,
|
|
||||||
this, &Shell::handleRemoteStderr);
|
|
||||||
connect(m_shell.get(), &QtcProcess::done, this, &Shell::handleChannelClosed);
|
|
||||||
m_shell->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Shell::handleShellStarted()
|
|
||||||
{
|
|
||||||
QSocketNotifier * const notifier = new QSocketNotifier(0, QSocketNotifier::Read, this);
|
|
||||||
connect(notifier, &QSocketNotifier::activated, this, &Shell::handleStdin);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Shell::handleRemoteStdout()
|
|
||||||
{
|
|
||||||
std::cout << m_shell->readAllStandardOutput().data() << std::flush;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Shell::handleRemoteStderr()
|
|
||||||
{
|
|
||||||
std::cerr << m_shell->readAllStandardError().data() << std::flush;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Shell::handleChannelClosed()
|
|
||||||
{
|
|
||||||
std::cerr << "Shell closed. Exit code was " << m_shell->exitCode() << "." << std::endl;
|
|
||||||
QCoreApplication::exit(m_shell->errorString().isEmpty() && m_shell->exitCode() == 0
|
|
||||||
? EXIT_SUCCESS : EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Shell::handleStdin()
|
|
||||||
{
|
|
||||||
m_shell->write(m_stdin->readLine());
|
|
||||||
}
|
|
@@ -1,60 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and The Qt Company. For licensing terms
|
|
||||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
||||||
** information use the contact form at https://www.qt.io/contact-us.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU
|
|
||||||
** General Public License version 3 as published by the Free Software
|
|
||||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
||||||
** included in the packaging of this file. Please review the following
|
|
||||||
** information to ensure the GNU General Public License requirements will
|
|
||||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <ssh/sshconnection.h>
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QByteArray;
|
|
||||||
class QFile;
|
|
||||||
class QString;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
class Shell : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
Shell(const QSsh::SshConnectionParameters ¶meters, QObject *parent = 0);
|
|
||||||
~Shell();
|
|
||||||
|
|
||||||
void run();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void handleConnected();
|
|
||||||
void handleConnectionError();
|
|
||||||
void handleRemoteStdout();
|
|
||||||
void handleRemoteStderr();
|
|
||||||
void handleShellMessage(const QString &message);
|
|
||||||
void handleChannelClosed();
|
|
||||||
void handleShellStarted();
|
|
||||||
void handleStdin();
|
|
||||||
|
|
||||||
QSsh::SshConnection *m_connection;
|
|
||||||
QSsh::SshRemoteProcessPtr m_shell;
|
|
||||||
QFile * const m_stdin;
|
|
||||||
};
|
|
@@ -1,6 +0,0 @@
|
|||||||
include(../ssh.pri)
|
|
||||||
QT += network
|
|
||||||
|
|
||||||
TARGET=shell
|
|
||||||
SOURCES=main.cpp shell.cpp argumentscollector.cpp
|
|
||||||
HEADERS=shell.h argumentscollector.h
|
|
@@ -1,27 +0,0 @@
|
|||||||
import qbs
|
|
||||||
import qbs.FileInfo
|
|
||||||
|
|
||||||
QtcManualtest {
|
|
||||||
name: "Manual ssh shell test"
|
|
||||||
condition: qbs.targetOS.contains("unix")
|
|
||||||
Depends { name: "Utils" }
|
|
||||||
Depends { name: "QtcSsh" }
|
|
||||||
Depends { name: "Qt.network" }
|
|
||||||
|
|
||||||
cpp.defines: {
|
|
||||||
var defines = base;
|
|
||||||
var absLibExecPath = FileInfo.joinPaths(qbs.installRoot, qbs.installPrefix,
|
|
||||||
qtc.ide_libexec_path);
|
|
||||||
var relLibExecPath = FileInfo.relativePath(destinationDirectory, absLibExecPath);
|
|
||||||
defines.push('TEST_RELATIVE_LIBEXEC_PATH="' + relLibExecPath + '"');
|
|
||||||
return defines;
|
|
||||||
}
|
|
||||||
|
|
||||||
files: [
|
|
||||||
"argumentscollector.cpp",
|
|
||||||
"argumentscollector.h",
|
|
||||||
"main.cpp",
|
|
||||||
"shell.cpp",
|
|
||||||
"shell.h",
|
|
||||||
]
|
|
||||||
}
|
|
@@ -1,17 +0,0 @@
|
|||||||
QT = core network
|
|
||||||
|
|
||||||
QTC_LIB_DEPENDS += ssh utils
|
|
||||||
include (../../../qtcreator.pri)
|
|
||||||
|
|
||||||
macx:QMAKE_LFLAGS += -Wl,-rpath,\"$$IDE_BIN_PATH/..\"
|
|
||||||
LIBS *= -L$$IDE_LIBRARY_PATH
|
|
||||||
unix {
|
|
||||||
QMAKE_LFLAGS += -Wl,-rpath,\"$$IDE_LIBRARY_PATH\"
|
|
||||||
}
|
|
||||||
|
|
||||||
CONFIG += console
|
|
||||||
CONFIG -= app_bundle
|
|
||||||
TEMPLATE = app
|
|
||||||
|
|
||||||
DEPENDPATH+=.
|
|
||||||
INCLUDEPATH+=.
|
|
@@ -1,8 +0,0 @@
|
|||||||
#-------------------------------------------------
|
|
||||||
#
|
|
||||||
# Project created by QtCreator 2010-07-01T09:44:44
|
|
||||||
#
|
|
||||||
#-------------------------------------------------
|
|
||||||
|
|
||||||
TEMPLATE = subdirs
|
|
||||||
SUBDIRS = shell
|
|
Reference in New Issue
Block a user