Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' into 'master'
Cleanups

See merge request !9
  • Loading branch information
pvuorela committed May 26, 2017
2 parents 35dba2b + aec4829 commit c2a459b
Show file tree
Hide file tree
Showing 27 changed files with 300 additions and 280 deletions.
2 changes: 1 addition & 1 deletion declarative/declarativessudeviceinfo.cpp
Expand Up @@ -26,7 +26,7 @@ QString DeclarativeSsuDeviceInfo::deviceModel()
return info.deviceModel();
}

QString DeclarativeSsuDeviceInfo::displayName(const int type)
QString DeclarativeSsuDeviceInfo::displayName(int type)
{
return info.displayName(type);
}
Expand Down
5 changes: 4 additions & 1 deletion declarative/declarativessudeviceinfo.h
Expand Up @@ -32,16 +32,19 @@ class DeclarativeSsuDeviceInfo : public QObject
* multithreaded environment, unless you like funny results.
*/
Q_INVOKABLE QString deviceFamily();

/**
* Try to find the device variant for the system this is running on.
* If the device is not a variant it will return an empty string. If
* fallback is set to true it return the device model in this case.
*/
Q_INVOKABLE QString deviceVariant(bool fallback = false);

/**
* Try to find out ond what kind of system this is running
*/
Q_INVOKABLE QString deviceModel();

/**
* Return a string suitable for display in dialogs, ...
*
Expand All @@ -52,7 +55,7 @@ class DeclarativeSsuDeviceInfo : public QObject
* If no manufacturer is found UNKNOWN is returned.
* For an invalid type an empty string is returned.
*/
Q_INVOKABLE QString displayName(const int type);
Q_INVOKABLE QString displayName(int type);

private:
SsuDeviceInfo info;
Expand Down
4 changes: 2 additions & 2 deletions libssu/sandbox.cpp
Expand Up @@ -79,7 +79,7 @@ Sandbox::~Sandbox()
}

if (!m_tempDir.isEmpty() && QFileInfo(m_tempDir).exists()) {
if (QProcess::execute("rm", QStringList() << "-rf" << m_tempDir) != 0) {
if (!QDir(m_tempDir).removeRecursively()) {
qWarning("%s: Failed to remove temporary directory", Q_FUNC_INFO);
}
}
Expand Down Expand Up @@ -276,7 +276,7 @@ bool Sandbox::prepare()

QString Sandbox::createTmpDir(const QString &nameTemplate)
{
static const int REASONABLE_REPEAT_COUNT = 10;
const int REASONABLE_REPEAT_COUNT = 10;

for (int i = 0; i < REASONABLE_REPEAT_COUNT; ++i) {
QString path;
Expand Down
60 changes: 33 additions & 27 deletions libssu/ssu.cpp
Expand Up @@ -37,7 +37,8 @@ static void restoreUid()
}
}

Ssu::Ssu(): QObject()
Ssu::Ssu()
: QObject()
{
errorFlag = false;
pendingRequests = 0;
Expand Down Expand Up @@ -75,13 +76,13 @@ Ssu::Ssu(): QObject()

// FIXME, the whole credentials stuff needs reworking
// should probably be part of repo handling instead of core configuration
QPair<QString, QString> Ssu::credentials(QString scope)
QPair<QString, QString> Ssu::credentials(const QString &scope)
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
return settings->credentials(scope);
}

QString Ssu::credentialsScope(QString repoName, bool rndRepo)
QString Ssu::credentialsScope(const QString &repoName, bool rndRepo)
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
SsuSettings repoSettings(SSU_REPO_CONFIGURATION, QSettings::IniFormat);
Expand Down Expand Up @@ -124,7 +125,7 @@ QString Ssu::credentialsScope(QString repoName, bool rndRepo)
return settings->credentialsScope(repoName, rndRepo);
}

QString Ssu::credentialsUrl(QString scope)
QString Ssu::credentialsUrl(const QString &scope)
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
return settings->credentialsUrl(scope);
Expand Down Expand Up @@ -178,19 +179,19 @@ void Ssu::setDeviceMode(Ssu::DeviceModeFlags mode, enum Ssu::EditMode editMode)
settings->setDeviceMode(mode, editMode);
}

void Ssu::setFlavour(QString flavour)
void Ssu::setFlavour(const QString &flavour)
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
settings->setFlavour(flavour);
}

void Ssu::setRelease(QString release, bool rnd)
void Ssu::setRelease(const QString &release, bool rnd)
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
settings->setRelease(release, rnd);
}

void Ssu::setDomain(QString domain)
void Ssu::setDomain(const QString &domain)
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
settings->setDomain(domain);
Expand Down Expand Up @@ -223,8 +224,9 @@ bool Ssu::registerDevice(QDomDocument *response)
settings->setValue("registered", false);
setError("Certificate is invalid");
return false;
} else
} else {
settings->setValue("certificate", certificate.toPem());
}

QString privateKeyString = response->elementsByTagName("privateKey").at(0).toElement().text();
QSslKey privateKey(privateKeyString.toLatin1(), QSsl::Rsa);
Expand All @@ -233,8 +235,9 @@ bool Ssu::registerDevice(QDomDocument *response)
settings->setValue("registered", false);
setError("Private key is invalid");
return false;
} else
} else {
settings->setValue("privateKey", privateKey.toPem());
}

// oldUser is just for reference purposes, in case we want to notify
// about owner changes for the device
Expand All @@ -256,7 +259,7 @@ bool Ssu::registerDevice(QDomDocument *response)

// RND repos have flavour (devel, testing, release), and release (latest, next)
// Release repos only have release (latest, next, version number)
QString Ssu::repoUrl(QString repoName, bool rndRepo,
QString Ssu::repoUrl(const QString &repoName, bool rndRepo,
QHash<QString, QString> repoParameters,
QHash<QString, QString> parametersOverride)
{
Expand Down Expand Up @@ -289,7 +292,7 @@ void Ssu::requestFinished(QNetworkReply *reply)

/// @TODO: indicate that the device is not registered if there's a 404 on credentials update url
if (settings->contains("home-url")) {
QString homeUrl = settings->value("home-url").toString().arg("");
QString homeUrl = settings->value("home-url").toString().arg(QString());
homeUrl.remove(QRegExp("//+$"));

if (request.url().toString().startsWith(homeUrl, Qt::CaseInsensitive)) {
Expand Down Expand Up @@ -353,11 +356,11 @@ void Ssu::requestFinished(QNetworkReply *reply)
}
}

void Ssu::sendRegistration(QString usernameDomain, QString password)
void Ssu::sendRegistration(const QString &usernameDomain, const QString &password)
{
errorFlag = false;

QString ssuCaCertificate, ssuRegisterUrl;
QString ssuRegisterUrl;
QString username, domainName;

SsuLog *ssuLog = SsuLog::instance();
Expand All @@ -381,7 +384,7 @@ void Ssu::sendRegistration(QString usernameDomain, QString password)
setDomain(settings->value("default-rnd-domain").toString());
}

ssuCaCertificate = SsuRepoManager::caCertificatePath();
QString ssuCaCertificate = SsuRepoManager::caCertificatePath();
if (ssuCaCertificate.isEmpty()) {
setError("CA certificate for ssu not set ('_ca-certificate in domain')");
return;
Expand All @@ -393,11 +396,12 @@ void Ssu::sendRegistration(QString usernameDomain, QString password)
setError("URL for ssu registration not set (config key 'register-url')");
return;
}
} else
} else {
ssuRegisterUrl = settings->value("register-url").toString();
}

QString IMEI = deviceInfo.deviceUid();
if (IMEI == "") {
if (IMEI.isEmpty()) {
setError("No valid UID available for your device. For phones: is your modem online?");
return;
}
Expand Down Expand Up @@ -432,10 +436,8 @@ void Ssu::sendRegistration(QString usernameDomain, QString password)
ssuLog->print(LOG_DEBUG, QString("Sending request to %1")
.arg(request.url().url()));

QNetworkReply *reply;

pendingRequests++;
reply = manager->post(request, form.query(QUrl::FullyEncoded).toStdString().c_str());
manager->post(request, form.query(QUrl::FullyEncoded).toStdString().c_str());
// we could expose downloadProgress() from reply in case we want progress info

QString homeUrl = settings->value("home-url").toString().arg(username);
Expand Down Expand Up @@ -482,7 +484,7 @@ bool Ssu::setCredentials(QDomDocument *response)
credentialScopes.append(scope);
}
} else {
setError("");
setError(QString());
return false;
}
}
Expand All @@ -494,7 +496,7 @@ bool Ssu::setCredentials(QDomDocument *response)
return true;
}

void Ssu::setError(QString errorMessage)
void Ssu::setError(const QString &errorMessage)
{
errorFlag = true;
errorString = errorMessage;
Expand All @@ -509,7 +511,7 @@ void Ssu::setError(QString errorMessage)
emit done();
}

void Ssu::storeAuthorizedKeys(QByteArray data)
void Ssu::storeAuthorizedKeys(const QByteArray &data)
{
QDir dir;
SsuLog *ssuLog = SsuLog::instance();
Expand Down Expand Up @@ -537,8 +539,9 @@ void Ssu::storeAuthorizedKeys(QByteArray data)
ssuLog->print(LOG_DEBUG, QString("Dropping to %1/%2 for writing authorized keys")
.arg(uid_min)
.arg(pw->pw_gid));
} else
} else {
return;
}

homePath = Sandbox::map(homePath);

Expand All @@ -549,13 +552,14 @@ void Ssu::storeAuthorizedKeys(QByteArray data)
return;
}

if (!dir.exists(homePath + "/.ssh"))
if (!dir.exists(homePath + "/.ssh")) {
if (!dir.mkdir(homePath + "/.ssh")) {
ssuLog->print(LOG_DEBUG, QString("Unable to create .ssh in %1")
.arg(homePath));
restoreUid();
return;
}
}

QFile::setPermissions(homePath + "/.ssh",
QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner);
Expand All @@ -579,7 +583,7 @@ void Ssu::updateCredentials(bool force)

SsuLog *ssuLog = SsuLog::instance();

if (deviceInfo.deviceUid() == "") {
if (deviceInfo.deviceUid().isEmpty()) {
setError("No valid UID available for your device. For phones: is your modem online?");
return;
}
Expand All @@ -597,8 +601,9 @@ void Ssu::updateCredentials(bool force)
setError("URL for credentials update not set (config key 'credentials-url')");
return;
}
} else
} else {
ssuCredentialsUrl = settings->value("credentials-url").toString();
}

if (!isRegistered()) {
setError("Device is not registered.");
Expand Down Expand Up @@ -661,8 +666,9 @@ void Ssu::updateStoreCredentials()
if (settings->value("ignore-credential-errors").toBool() == true) {
ssuLog->print(LOG_WARNING, QString("Warning: ignore-credential-errors is set, passing auth errors down to libzypp"));
ssuLog->print(LOG_WARNING, QString("Store credentials not received. %1").arg(reply.error().message()));
} else
} else {
setError(QString("Store credentials not received. %1").arg(reply.error().message()));
}
} else {
SsuCoreConfig *settings = SsuCoreConfig::instance();
settings->beginGroup("credentials-store");
Expand Down
20 changes: 10 additions & 10 deletions libssu/ssu.h
Expand Up @@ -85,7 +85,7 @@ class Ssu: public QObject
* Find a username/password pair for the given scope
* @return a QPair with username and password, or an empty QPair if scope is invalid
*/
QPair<QString, QString> credentials(QString scope);
QPair<QString, QString> credentials(const QString &scope);
/**
* Get the scope for a repository, taking into account different scopes for
* release and RnD repositories
Expand All @@ -95,11 +95,11 @@ class Ssu: public QObject
*
* @return a string containing the scope; it can be used to look up login credentials using credentials()
*/
QString credentialsScope(QString repoName, bool rndRepo = false);
QString credentialsScope(const QString &repoName, bool rndRepo = false);
/**
* Return the URL for which credentials scope is valid
*/
QString credentialsUrl(QString scope);
QString credentialsUrl(const QString &scope);
/**
* Returns if the last operation was successful
* @retval true last operation was successful
Expand All @@ -116,7 +116,7 @@ class Ssu: public QObject
* Resolve a repository url
* @return the repository URL on success, an empty string on error
*/
QString repoUrl(QString repoName, bool rndRepo = false,
QString repoUrl(const QString &repoName, bool rndRepo = false,
QHash<QString, QString> repoParameters = QHash<QString, QString>(),
QHash<QString, QString> parametersOverride = QHash<QString, QString>());
/**
Expand Down Expand Up @@ -146,11 +146,11 @@ class Ssu: public QObject
/// See SsuCoreConfig::setDeviceMode
Q_INVOKABLE void setDeviceMode(DeviceModeFlags mode, enum EditMode editMode = Replace);
/// See SsuCoreConfig::setFlavour
Q_INVOKABLE void setFlavour(QString flavour);
Q_INVOKABLE void setFlavour(const QString &flavour);
/// See SsuCoreConfig::setRelease
Q_INVOKABLE void setRelease(QString release, bool rnd = false);
Q_INVOKABLE void setRelease(const QString &release, bool rnd = false);
/// See SsuCoreConfig::setDomain
Q_INVOKABLE void setDomain(QString domain);
Q_INVOKABLE void setDomain(const QString &domain);
/// See SsuCoreConfig::useSslVerify
Q_INVOKABLE bool useSslVerify();

Expand All @@ -162,15 +162,15 @@ class Ssu: public QObject
bool registerDevice(QDomDocument *response);
bool setCredentials(QDomDocument *response);
bool verifyResponse(QDomDocument *response);
void storeAuthorizedKeys(QByteArray data);
void storeAuthorizedKeys(const QByteArray &data);

private slots:
void requestFinished(QNetworkReply *reply);
/**
* Set errorString returned by lastError to errorMessage, set
* errorFlag returned by error() to true, and emit done()
*/
void setError(QString errorMessage);
void setError(const QString &errorMessage);

public slots:
/**
Expand All @@ -182,7 +182,7 @@ public slots:
* error() to check if an error occured, and use lastError() to retrieve the last
* error message.
*/
void sendRegistration(QString username, QString password);
void sendRegistration(const QString &username, const QString &password);
/**
* Try to update the RND repository credentials. The device needs to be registered
* for this to work. updateCredentials remembers the time of the last credentials
Expand Down

0 comments on commit c2a459b

Please sign in to comment.