Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Cosmetic style changes
  • Loading branch information
pvuorela committed May 24, 2017
1 parent 16541f8 commit 0d8b99f
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 104 deletions.
3 changes: 3 additions & 0 deletions 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 Down
2 changes: 1 addition & 1 deletion libssu/sandbox.cpp
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
28 changes: 18 additions & 10 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 @@ -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 Down Expand Up @@ -357,7 +360,7 @@ void Ssu::sendRegistration(QString usernameDomain, 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,8 +396,9 @@ 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 == "") {
Expand Down Expand Up @@ -535,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 @@ -547,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 Down Expand Up @@ -595,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 @@ -659,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
3 changes: 2 additions & 1 deletion libssu/ssucoreconfig.cpp
Expand Up @@ -111,8 +111,9 @@ void SsuCoreConfig::setDeviceMode(Ssu::DeviceModeFlags mode, enum Ssu::EditMode
oldMode |= mode;
} else if ((editMode & Ssu::Remove) == Ssu::Remove) {
oldMode &= ~mode;
} else
} else {
oldMode = mode;
}

setValue("deviceMode", oldMode);
sync();
Expand Down
12 changes: 5 additions & 7 deletions libssu/ssudeviceinfo.cpp
Expand Up @@ -23,7 +23,8 @@

#include "../constants.h"

SsuDeviceInfo::SsuDeviceInfo(QString model): QObject()
SsuDeviceInfo::SsuDeviceInfo(const QString &model)
: QObject()
{
boardMappings = new SsuSettings(SSU_BOARD_MAPPING_CONFIGURATION, SSU_BOARD_MAPPING_CONFIGURATION_DIR);
if (!model.isEmpty())
Expand Down Expand Up @@ -160,19 +161,16 @@ QString SsuDeviceInfo::deviceVariant(bool fallback)

QString SsuDeviceInfo::deviceModel()
{
QDir dir;
QFile procCpuinfo;
QStringList keys;

if (!cachedModel.isEmpty())
return cachedModel;

boardMappings->beginGroup("file.exists");
keys = boardMappings->allKeys();
QStringList keys = boardMappings->allKeys();

// check if the device can be identified by testing for a file
foreach (const QString &key, keys) {
QString value = boardMappings->value(key).toString();
QDir dir;
if (dir.exists(Sandbox::map(value))) {
cachedModel = key;
break;
Expand All @@ -182,6 +180,7 @@ QString SsuDeviceInfo::deviceModel()
if (!cachedModel.isEmpty()) return cachedModel;

// check if the device can be identified by a string in /proc/cpuinfo
QFile procCpuinfo;
procCpuinfo.setFileName(Sandbox::map("/proc/cpuinfo"));
procCpuinfo.open(QIODevice::ReadOnly | QIODevice::Text);
if (procCpuinfo.isOpen()) {
Expand Down Expand Up @@ -347,7 +346,6 @@ QString SsuDeviceInfo::displayName(const int type)
QString variant = deviceVariant(false);
QString value, key;


switch (type) {
case Ssu::DeviceManufacturer:
key = "/deviceManufacturer";
Expand Down
13 changes: 12 additions & 1 deletion libssu/ssudeviceinfo.h
Expand Up @@ -30,43 +30,51 @@ class SsuDeviceInfo: public QObject
* Return the list of adaptations used for the set model
*/
QStringList adaptationRepos();

/**
* Resolve adaptation-specific variables for adaptationName, and store them in storageHash
* Returns "adaptation" if a valid adaptation was found, adaptationName otherwise
*/
QString adaptationVariables(const QString &adaptationName, QHash<QString, QString> *storageHash);

/**
* Check if a given model is available in the deviceinfo database, either directly,
* or as variant. If no model is provided as argument the autodetected or previously
* set model is used.
*/
bool contains(const QString &model = "");

/**
* Try to find the device family for the system this is running on. This function
* temporarily changes the detected model, and therefore should not be used in a
* 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();

/**
* Calculate the device ID used in ssu requests
* @return The first imei from oFono ModemManager API, if available, or WLAN mac address, or device uid fallback code similar to QDeviceInfo::uniqueDeviceID()
*/
Q_INVOKABLE QString deviceUid();

/**
* Return the list of repositories explicitely disabled for this device
* This does not include repositories only disabled in the user configuration.
*/
QStringList disabledRepos();

/**
* Return a string suitable for display in dialogs, ...
*
Expand All @@ -85,22 +93,26 @@ class SsuDeviceInfo: public QObject
* Disabled repositories are excluded depending on filter settings.
*/
QStringList repos(bool rnd = false, int filter = Ssu::NoFilter);

/**
* Override device model autodetection
*/
Q_INVOKABLE void setDeviceModel(QString model = "");

/**
* Return a variable from the given variable section. 'var'- is automatically
* prepended to the section name if not specified already. Recursive search
* through several variable sections (specified in the section) is supported,
* returned will be the first occurence of the variable.
*/
QVariant variable(QString section, const QString &key);

/**
* Return the requested variable section. 'var-' is automatically
* prepended to the section name if not specified already.
*/
void variableSection(QString section, QHash<QString, QString> *storageHash);

/**
* Return a value from an adaptation section. Returns an empty string
* or a given default value if key does not exist.
Expand All @@ -111,7 +123,6 @@ class SsuDeviceInfo: public QObject
*/
QVariant value(const QString &key, const QVariant &value = QVariant());


private:
SsuSettings *boardMappings;
QString cachedFamily, cachedModel, cachedVariant;
Expand Down
3 changes: 2 additions & 1 deletion libssu/ssufeaturemanager.cpp
Expand Up @@ -18,7 +18,8 @@

#include "../constants.h"

SsuFeatureManager::SsuFeatureManager(): QObject()
SsuFeatureManager::SsuFeatureManager()
: QObject()
{
featureSettings = new SsuSettings(SSU_FEATURE_CONFIGURATION, SSU_FEATURE_CONFIGURATION_DIR);
}
Expand Down
6 changes: 3 additions & 3 deletions libssu/ssulog.cpp
Expand Up @@ -26,9 +26,6 @@ SsuLog *SsuLog::instance()

void SsuLog::print(int priority, QString message)
{
QByteArray ba = message.toUtf8();
const char *ca = ba.constData();

// directly go through qsettings here to avoid recursive invocation
// of coreconfig / ssulog
if (ssuLogLevel == -1) {
Expand All @@ -45,6 +42,9 @@ void SsuLog::print(int priority, QString message)
if (priority > ssuLogLevel)
return;

QByteArray ba = message.toUtf8();
const char *ca = ba.constData();

if (sd_journal_print(priority, "ssu: %s", ca) < 0 && fallbackLogPath != "") {
QFile logfile;
QTextStream logstream;
Expand Down

0 comments on commit 0d8b99f

Please sign in to comment.