Combine some SshConnectionParameter members

Combine host, port, username and password into a 'url' member and
add some convenience accessors.

Change-Id: Iddc26ff00dad1285c96aa56f196dbc4febe8e974
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2017-12-19 12:45:46 +01:00
parent b64c1a96b8
commit 21c66ce5fd
20 changed files with 80 additions and 86 deletions

View File

@@ -63,21 +63,21 @@ namespace QSsh {
const QByteArray ClientId("SSH-2.0-QtCreator\r\n");
SshConnectionParameters::SshConnectionParameters() :
timeout(0), authenticationType(AuthenticationTypePublicKey), port(0),
timeout(0), authenticationType(AuthenticationTypePublicKey),
hostKeyCheckingMode(SshHostKeyCheckingNone)
{
url.setPort(0);
options |= SshIgnoreDefaultProxy;
options |= SshEnableStrictConformanceChecks;
}
static inline bool equals(const SshConnectionParameters &p1, const SshConnectionParameters &p2)
{
return p1.host == p2.host && p1.userName == p2.userName
return p1.url == p2.url
&& p1.authenticationType == p2.authenticationType
&& (p1.authenticationType == SshConnectionParameters::AuthenticationTypePassword ?
p1.password == p2.password : p1.privateKeyFile == p2.privateKeyFile)
&& p1.privateKeyFile == p2.privateKeyFile
&& p1.hostKeyCheckingMode == p2.hostKeyCheckingMode
&& p1.timeout == p2.timeout && p1.port == p2.port;
&& p1.timeout == p2.timeout;
}
bool operator==(const SshConnectionParameters &p1, const SshConnectionParameters &p2)
@@ -521,11 +521,11 @@ void SshConnectionPrivate::handleServiceAcceptPacket()
m_triedAllPasswordBasedMethods = false;
// Fall-through.
case SshConnectionParameters::AuthenticationTypePassword:
m_sendFacility.sendUserAuthByPasswordRequestPacket(m_connParams.userName.toUtf8(),
SshCapabilities::SshConnectionService, m_connParams.password.toUtf8());
m_sendFacility.sendUserAuthByPasswordRequestPacket(m_connParams.userName().toUtf8(),
SshCapabilities::SshConnectionService, m_connParams.password().toUtf8());
break;
case SshConnectionParameters::AuthenticationTypeKeyboardInteractive:
m_sendFacility.sendUserAuthByKeyboardInteractiveRequestPacket(m_connParams.userName.toUtf8(),
m_sendFacility.sendUserAuthByKeyboardInteractiveRequestPacket(m_connParams.userName().toUtf8(),
SshCapabilities::SshConnectionService);
break;
case SshConnectionParameters::AuthenticationTypePublicKey:
@@ -575,7 +575,7 @@ void SshConnectionPrivate::handleUserAuthInfoRequestPacket()
// Not very interactive, admittedly, but we don't want to be for now.
for (int i = 0; i < requestPacket.prompts.count(); ++i)
responses << m_connParams.password;
responses << m_connParams.password();
m_sendFacility.sendUserAuthInfoResponsePacket(responses);
}
@@ -626,7 +626,7 @@ void SshConnectionPrivate::handleUserAuthFailurePacket()
&& !m_triedAllPasswordBasedMethods) {
m_triedAllPasswordBasedMethods = true;
m_sendFacility.sendUserAuthByKeyboardInteractiveRequestPacket(
m_connParams.userName.toUtf8(),
m_connParams.userName().toUtf8(),
SshCapabilities::SshConnectionService);
return;
}
@@ -840,7 +840,7 @@ void SshConnectionPrivate::tryAllAgentKeys()
qCDebug(sshLog) << "trying authentication with" << keys.count()
<< "public keys received from agent";
foreach (const QByteArray &key, keys) {
m_sendFacility.sendQueryPublicKeyPacket(m_connParams.userName.toUtf8(),
m_sendFacility.sendQueryPublicKeyPacket(m_connParams.userName().toUtf8(),
SshCapabilities::SshConnectionService, key);
m_pendingKeyChecks.enqueue(key);
}
@@ -860,7 +860,7 @@ void SshConnectionPrivate::authenticateWithPublicKey()
signature = m_agentSignature;
}
m_sendFacility.sendUserAuthByPublicKeyRequestPacket(m_connParams.userName.toUtf8(),
m_sendFacility.sendUserAuthByPublicKeyRequestPacket(m_connParams.userName().toUtf8(),
SshCapabilities::SshConnectionService, key, signature);
}
@@ -929,7 +929,7 @@ void SshConnectionPrivate::connectToHost()
m_state = SocketConnecting;
m_keyExchangeState = NoKeyExchange;
m_timeoutTimer.start();
m_socket->connectToHost(m_connParams.host, m_connParams.port);
m_socket->connectToHost(m_connParams.host(), m_connParams.port());
}
void SshConnectionPrivate::closeConnection(SshErrorCode sshError,

View File

@@ -36,6 +36,7 @@
#include <QSharedPointer>
#include <QString>
#include <QHostAddress>
#include <QUrl>
namespace QSsh {
class SftpChannel;
@@ -75,13 +76,19 @@ public:
SshConnectionParameters();
QString host;
QString userName;
QString password;
QString host() const { return url.host(); }
quint16 port() const { return url.port(); }
QString userName() const { return url.userName(); }
QString password() const { return url.password(); }
void setHost(const QString &host) { url.setHost(host); }
void setPort(int port) { url.setPort(port); }
void setUserName(const QString &name) { url.setUserName(name); }
void setPassword(const QString &password) { url.setPassword(password); }
QUrl url;
QString privateKeyFile;
int timeout; // In seconds.
AuthenticationType authenticationType;
quint16 port;
SshConnectionOptions options;
SshHostKeyCheckingMode hostKeyCheckingMode;
SshHostKeyDatabasePtr hostKeyDatabase;

View File

@@ -237,7 +237,7 @@ void SshKeyExchange::checkHostKey(const QByteArray &hostKey)
{
if (m_connParams.hostKeyCheckingMode == SshHostKeyCheckingNone) {
if (m_connParams.hostKeyDatabase)
m_connParams.hostKeyDatabase->insertHostKey(m_connParams.host, hostKey);
m_connParams.hostKeyDatabase->insertHostKey(m_connParams.host(), hostKey);
return;
}
@@ -247,7 +247,7 @@ void SshKeyExchange::checkHostKey(const QByteArray &hostKey)
"if host key checking is enabled."));
}
switch (m_connParams.hostKeyDatabase->matchHostKey(m_connParams.host, hostKey)) {
switch (m_connParams.hostKeyDatabase->matchHostKey(m_connParams.host(), hostKey)) {
case SshHostKeyDatabase::KeyLookupMatch:
return; // Nothing to do.
case SshHostKeyDatabase::KeyLookupMismatch:
@@ -259,14 +259,14 @@ void SshKeyExchange::checkHostKey(const QByteArray &hostKey)
throwHostKeyException();
break;
}
m_connParams.hostKeyDatabase->insertHostKey(m_connParams.host, hostKey);
m_connParams.hostKeyDatabase->insertHostKey(m_connParams.host(), hostKey);
}
void SshKeyExchange::throwHostKeyException()
{
throw SshServerException(SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE, "Host key changed",
SSH_TR("Host key of machine \"%1\" has changed.")
.arg(m_connParams.host));
.arg(m_connParams.host()));
}
} // namespace Internal

View File

@@ -104,8 +104,8 @@ void BareMetalDevice::setChannelByServerProvider(GdbServerProvider *provider)
if (colon < 0)
return;
QSsh::SshConnectionParameters sshParams = sshParameters();
sshParams.host = channel.left(colon);
sshParams.port = channel.mid(colon + 1).toUShort();
sshParams.setHost(channel.left(colon));
sshParams.setPort(channel.mid(colon + 1).toUShort());
setSshParameters(sshParams);
}
@@ -121,8 +121,8 @@ void BareMetalDevice::fromMap(const QVariantMap &map)
const QSsh::SshConnectionParameters sshParams = sshParameters();
DefaultGdbServerProvider *newProvider = new DefaultGdbServerProvider;
newProvider->setDisplayName(name);
newProvider->m_host = sshParams.host;
newProvider->m_port = sshParams.port;
newProvider->m_host = sshParams.host();
newProvider->m_port = sshParams.port();
if (GdbServerProviderManager::registerProvider(newProvider))
gdbServerProvider = newProvider->id();
else

View File

@@ -64,7 +64,7 @@ StartRemoteDialog::StartRemoteDialog(QWidget *parent)
d->kitChooser = new KitChooser(this);
d->kitChooser->setKitPredicate([](const Kit *kit) {
const IDevice::ConstPtr device = DeviceKitInformation::device(kit);
return kit->isValid() && device && !device->sshParameters().host.isEmpty();
return kit->isValid() && device && !device->sshParameters().host().isEmpty();
});
d->executable = new QLineEdit(this);
d->arguments = new QLineEdit(this);

View File

@@ -429,7 +429,7 @@ void StartApplicationDialog::run(bool attachRemote)
if (!inputAddress.isEmpty())
debugger->setRemoteChannel(inputAddress);
else
debugger->setRemoteChannel(dev->sshParameters().host, newParameters.serverPort);
debugger->setRemoteChannel(dev->sshParameters().host(), newParameters.serverPort);
debugger->setRunControlName(newParameters.displayName());
debugger->setBreakOnMain(newParameters.breakAtMain);
debugger->setDebugInfoLocation(newParameters.debugInfoLocation);

View File

@@ -2141,7 +2141,7 @@ void DebuggerPluginPrivate::attachToQmlPort()
debugger->setQmlServer(qmlServer);
QSsh::SshConnectionParameters sshParameters = device->sshParameters();
debugger->setRemoteChannel(sshParameters.host, sshParameters.port);
debugger->setRemoteChannel(sshParameters.host(), sshParameters.port());
debugger->setStartMode(AttachToQmlServer);
debugger->startRunControl();

View File

@@ -972,7 +972,7 @@ Port GdbServerPortsGatherer::gdbServerPort() const
QString GdbServerPortsGatherer::gdbServerChannel() const
{
QUrl url = channel(0);
const QString host = m_device->sshParameters().host;
const QString host = m_device->sshParameters().host();
return QString("%1:%2").arg(host).arg(url.port());
}

View File

@@ -272,7 +272,7 @@ public:
m_channelForwarder->setFromUrlGetter([this] {
QUrl url;
url.setScheme(urlTcpScheme());
url.setHost(device()->sshParameters().host);
url.setHost(device()->sshParameters().host());
url.setPort(m_portGatherer->findPort().number());
return url;
});

View File

@@ -332,12 +332,12 @@ void IDevice::fromMap(const QVariantMap &map)
d->id = newId();
d->origin = static_cast<Origin>(map.value(QLatin1String(OriginKey), ManuallyAdded).toInt());
d->sshParameters.host = map.value(QLatin1String(HostKey)).toString();
d->sshParameters.port = map.value(QLatin1String(SshPortKey), 22).toInt();
d->sshParameters.userName = map.value(QLatin1String(UserNameKey)).toString();
d->sshParameters.setHost(map.value(QLatin1String(HostKey)).toString());
d->sshParameters.setPort(map.value(QLatin1String(SshPortKey), 22).toInt());
d->sshParameters.setUserName(map.value(QLatin1String(UserNameKey)).toString());
d->sshParameters.authenticationType
= static_cast<AuthType>(map.value(QLatin1String(AuthKey), DefaultAuthType).toInt());
d->sshParameters.password = map.value(QLatin1String(PasswordKey)).toString();
d->sshParameters.setPassword(map.value(QLatin1String(PasswordKey)).toString());
d->sshParameters.privateKeyFile = map.value(QLatin1String(KeyFileKey), defaultPrivateKeyFilePath()).toString();
d->sshParameters.timeout = map.value(QLatin1String(TimeoutKey), DefaultTimeout).toInt();
d->sshParameters.hostKeyCheckingMode = static_cast<QSsh::SshHostKeyCheckingMode>
@@ -371,11 +371,11 @@ QVariantMap IDevice::toMap() const
map.insert(QLatin1String(OriginKey), d->origin);
map.insert(QLatin1String(MachineTypeKey), d->machineType);
map.insert(QLatin1String(HostKey), d->sshParameters.host);
map.insert(QLatin1String(SshPortKey), d->sshParameters.port);
map.insert(QLatin1String(UserNameKey), d->sshParameters.userName);
map.insert(QLatin1String(HostKey), d->sshParameters.host());
map.insert(QLatin1String(SshPortKey), d->sshParameters.port());
map.insert(QLatin1String(UserNameKey), d->sshParameters.userName());
map.insert(QLatin1String(AuthKey), d->sshParameters.authenticationType);
map.insert(QLatin1String(PasswordKey), d->sshParameters.password);
map.insert(QLatin1String(PasswordKey), d->sshParameters.password());
map.insert(QLatin1String(KeyFileKey), d->sshParameters.privateKeyFile);
map.insert(QLatin1String(TimeoutKey), d->sshParameters.timeout);
map.insert(QLatin1String(HostKeyCheckingKey), d->sshParameters.hostKeyCheckingMode);
@@ -416,7 +416,7 @@ QUrl IDevice::toolControlChannel(const ControlChannelHint &) const
{
QUrl url;
url.setScheme(Utils::urlTcpScheme());
url.setHost(d->sshParameters.host);
url.setHost(d->sshParameters.host());
return url;
}

View File

@@ -696,17 +696,17 @@ void DeviceKitInformation::addToMacroExpander(Kit *kit, Utils::MacroExpander *ex
expander->registerVariable("Device:HostAddress", tr("Host address"),
[kit]() -> QString {
const IDevice::ConstPtr device = DeviceKitInformation::device(kit);
return device ? device->sshParameters().host : QString();
return device ? device->sshParameters().host() : QString();
});
expander->registerVariable("Device:SshPort", tr("SSH port"),
[kit]() -> QString {
const IDevice::ConstPtr device = DeviceKitInformation::device(kit);
return device ? QString::number(device->sshParameters().port) : QString();
return device ? QString::number(device->sshParameters().port()) : QString();
});
expander->registerVariable("Device:UserName", tr("User name"),
[kit]() -> QString {
const IDevice::ConstPtr device = DeviceKitInformation::device(kit);
return device ? device->sshParameters().userName : QString();
return device ? device->sshParameters().userName() : QString();
});
expander->registerVariable("Device:KeyFile", tr("Private key file"),
[kit]() -> QString {

View File

@@ -1422,7 +1422,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
[]() -> QString {
Kit *kit = currentKit();
const IDevice::ConstPtr device = DeviceKitInformation::device(kit);
return device ? device->sshParameters().host : QString();
return device ? device->sshParameters().host() : QString();
});
expander->registerVariable("CurrentDevice:SshPort",
@@ -1430,7 +1430,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
[]() -> QString {
Kit *kit = currentKit();
const IDevice::ConstPtr device = DeviceKitInformation::device(kit);
return device ? QString::number(device->sshParameters().port) : QString();
return device ? QString::number(device->sshParameters().port()) : QString();
});
expander->registerVariable("CurrentDevice:UserName",
@@ -1438,7 +1438,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
[]() -> QString {
Kit *kit = currentKit();
const IDevice::ConstPtr device = DeviceKitInformation::device(kit);
return device ? device->sshParameters().userName : QString();
return device ? device->sshParameters().userName() : QString();
});

View File

@@ -70,7 +70,7 @@ void QnxQmlProfilerSupport::start()
Port qmlPort = m_portsGatherer->findPort();
QUrl serverUrl;
serverUrl.setHost(device()->sshParameters().host);
serverUrl.setHost(device()->sshParameters().host());
serverUrl.setPort(qmlPort.number());
serverUrl.setScheme("tcp");
m_profiler->recordData("QmlServerUrl", serverUrl);

View File

@@ -64,15 +64,11 @@ IDevice::Ptr QnxDeviceWizard::device()
{
QSsh::SshConnectionParameters sshParams;
sshParams.options = QSsh::SshIgnoreDefaultProxy;
sshParams.host = m_setupPage->hostName();
sshParams.userName = m_setupPage->userName();
sshParams.port = 22;
sshParams.url = m_setupPage->url();
sshParams.timeout = 10;
sshParams.authenticationType = m_setupPage->authenticationType();
if (sshParams.authenticationType == QSsh::SshConnectionParameters::AuthenticationTypeTryAllPasswordBasedMethods
|| sshParams.authenticationType == QSsh::SshConnectionParameters::AuthenticationTypePassword)
sshParams.password = m_setupPage->password();
else
if (sshParams.authenticationType != QSsh::SshConnectionParameters::AuthenticationTypeTryAllPasswordBasedMethods
&& sshParams.authenticationType != QSsh::SshConnectionParameters::AuthenticationTypePassword)
sshParams.privateKeyFile = m_setupPage->privateKeyFilePath();
QnxDevice::Ptr device = QnxDevice::create(m_setupPage->configurationName(),

View File

@@ -97,7 +97,7 @@ void DeploymentTimeInfo::saveDeploymentTimeStamp(const DeployableFile &deployabl
systemRoot = SysRootKitInformation::sysRoot(kit).toString();
const IDevice::ConstPtr deviceConfiguration = DeviceKitInformation::device(kit);
const QString host = deviceConfiguration->sshParameters().host;
const QString host = deviceConfiguration->sshParameters().host();
d->lastDeployed.insert(
DeployParameters(deployableFile, host, systemRoot),
@@ -115,7 +115,7 @@ bool DeploymentTimeInfo::hasChangedSinceLastDeployment(const DeployableFile &dep
systemRoot = SysRootKitInformation::sysRoot(kit).toString();
const IDevice::ConstPtr deviceConfiguration = DeviceKitInformation::device(kit);
const QString host = deviceConfiguration->sshParameters().host;
const QString host = deviceConfiguration->sshParameters().host();
const DeployParameters dp(deployableFile, host, systemRoot);

View File

@@ -106,14 +106,14 @@ void GenericLinuxDeviceConfigurationWidget::authenticationTypeChanged()
void GenericLinuxDeviceConfigurationWidget::hostNameEditingFinished()
{
SshConnectionParameters sshParams = device()->sshParameters();
sshParams.host = m_ui->hostLineEdit->text().trimmed();
sshParams.setHost(m_ui->hostLineEdit->text().trimmed());
device()->setSshParameters(sshParams);
}
void GenericLinuxDeviceConfigurationWidget::sshPortEditingFinished()
{
SshConnectionParameters sshParams = device()->sshParameters();
sshParams.port = m_ui->sshPortSpinBox->value();
sshParams.setPort(m_ui->sshPortSpinBox->value());
device()->setSshParameters(sshParams);
}
@@ -127,14 +127,14 @@ void GenericLinuxDeviceConfigurationWidget::timeoutEditingFinished()
void GenericLinuxDeviceConfigurationWidget::userNameEditingFinished()
{
SshConnectionParameters sshParams = device()->sshParameters();
sshParams.userName = m_ui->userLineEdit->text();
sshParams.setUserName(m_ui->userLineEdit->text());
device()->setSshParameters(sshParams);
}
void GenericLinuxDeviceConfigurationWidget::passwordEditingFinished()
{
SshConnectionParameters sshParams = device()->sshParameters();
sshParams.password = m_ui->pwdLineEdit->text();
sshParams.setPassword(m_ui->pwdLineEdit->text());
device()->setSshParameters(sshParams);
}
@@ -235,12 +235,12 @@ void GenericLinuxDeviceConfigurationWidget::initGui()
m_ui->sshPortSpinBox->setEnabled(!device()->isAutoDetected());
m_ui->hostKeyCheckBox->setChecked(sshParams.hostKeyCheckingMode != SshHostKeyCheckingNone);
m_ui->hostLineEdit->setText(sshParams.host);
m_ui->sshPortSpinBox->setValue(sshParams.port);
m_ui->hostLineEdit->setText(sshParams.host());
m_ui->sshPortSpinBox->setValue(sshParams.port());
m_ui->portsLineEdit->setText(device()->freePorts().toString());
m_ui->timeoutSpinBox->setValue(sshParams.timeout);
m_ui->userLineEdit->setText(sshParams.userName);
m_ui->pwdLineEdit->setText(sshParams.password);
m_ui->userLineEdit->setText(sshParams.userName());
m_ui->pwdLineEdit->setText(sshParams.password());
m_ui->keyFileLineEdit->setPath(sshParams.privateKeyFile);
m_ui->showPasswordCheckBox->setChecked(false);
m_ui->gdbServerLineEdit->setText(device()->debugServerPath());

View File

@@ -72,14 +72,10 @@ IDevice::Ptr GenericLinuxDeviceConfigurationWizard::device()
{
SshConnectionParameters sshParams;
sshParams.options &= ~SshConnectionOptions(SshEnableStrictConformanceChecks); // For older SSH servers.
sshParams.host = d->setupPage.hostName();
sshParams.userName = d->setupPage.userName();
sshParams.port = 22;
sshParams.url = d->setupPage.url();
sshParams.timeout = 10;
sshParams.authenticationType = d->setupPage.authenticationType();
if (sshParams.authenticationType != SshConnectionParameters::AuthenticationTypePublicKey)
sshParams.password = d->setupPage.password();
else
if (sshParams.authenticationType == SshConnectionParameters::AuthenticationTypePublicKey)
sshParams.privateKeyFile = d->setupPage.privateKeyFilePath();
IDevice::Ptr device = LinuxDevice::create(d->setupPage.configurationName(),
Core::Id(Constants::GenericLinuxOsType), IDevice::Hardware);

View File

@@ -88,7 +88,9 @@ void GenericLinuxDeviceConfigurationWizardSetupPage::initializePage()
bool GenericLinuxDeviceConfigurationWizardSetupPage::isComplete() const
{
return !configurationName().isEmpty() && !hostName().isEmpty() && !userName().isEmpty()
return !configurationName().isEmpty()
&& !d->ui.hostNameLineEdit->text().trimmed().isEmpty()
&& !d->ui.userNameLineEdit->text().trimmed().isEmpty()
&& (authenticationType() != SshConnectionParameters::AuthenticationTypePublicKey
|| d->ui.privateKeyPathChooser->isValid());
}
@@ -98,14 +100,14 @@ QString GenericLinuxDeviceConfigurationWizardSetupPage::configurationName() cons
return d->ui.nameLineEdit->text().trimmed();
}
QString GenericLinuxDeviceConfigurationWizardSetupPage::hostName() const
QUrl GenericLinuxDeviceConfigurationWizardSetupPage::url() const
{
return d->ui.hostNameLineEdit->text().trimmed();
}
QString GenericLinuxDeviceConfigurationWizardSetupPage::userName() const
{
return d->ui.userNameLineEdit->text().trimmed();
QUrl url;
url.setHost(d->ui.hostNameLineEdit->text().trimmed());
url.setUserName(d->ui.userNameLineEdit->text().trimmed());
url.setPassword(d->ui.passwordLineEdit->text());
url.setPort(22);
return url;
}
SshConnectionParameters::AuthenticationType GenericLinuxDeviceConfigurationWizardSetupPage::authenticationType() const
@@ -116,11 +118,6 @@ SshConnectionParameters::AuthenticationType GenericLinuxDeviceConfigurationWizar
: SshConnectionParameters::AuthenticationTypeAgent;
}
QString GenericLinuxDeviceConfigurationWizardSetupPage::password() const
{
return d->ui.passwordLineEdit->text();
}
QString GenericLinuxDeviceConfigurationWizardSetupPage::privateKeyFilePath() const
{
return d->ui.privateKeyPathChooser->path();

View File

@@ -49,10 +49,8 @@ public:
bool isComplete() const;
QString configurationName() const;
QString hostName() const;
QString userName() const;
QUrl url() const;
QSsh::SshConnectionParameters::AuthenticationType authenticationType() const;
QString password() const;
QString privateKeyFilePath() const;
virtual QString defaultConfigurationName() const;

View File

@@ -62,7 +62,7 @@ void RemoteLinuxQmlToolingSupport::start()
QUrl serverUrl;
serverUrl.setScheme(urlTcpScheme());
serverUrl.setHost(device()->sshParameters().host);
serverUrl.setHost(device()->sshParameters().host());
serverUrl.setPort(qmlPort.number());
m_runworker->recordData("QmlServerUrl", serverUrl);