From 309ebecb0829d3d1240b5a704dbd133b189f0b53 Mon Sep 17 00:00:00 2001 From: Pekka Vuorela Date: Tue, 23 May 2017 18:01:22 +0300 Subject: [PATCH] [ssu] Use consistently const QString & on interfaces. Contributes to JB#38781 Plus some similar other interface details. --- declarative/declarativessudeviceinfo.cpp | 2 +- declarative/declarativessudeviceinfo.h | 2 +- libssu/ssu.cpp | 20 ++++---- libssu/ssu.h | 20 ++++---- libssu/ssucoreconfig.cpp | 14 +++--- libssu/ssucoreconfig_p.h | 12 ++--- libssu/ssudeviceinfo.cpp | 22 +++++---- libssu/ssudeviceinfo.h | 11 +++-- libssu/ssufeaturemanager.cpp | 2 +- libssu/ssufeaturemanager.h | 2 +- libssu/ssulog.cpp | 2 +- libssu/ssulog_p.h | 2 +- libssu/ssurepomanager.cpp | 35 +++++++------- libssu/ssurepomanager.h | 12 ++--- libssu/ssuvariables.cpp | 59 +++++++++++++----------- libssu/ssuvariables_p.h | 18 ++++---- ssucli/ssucli.cpp | 2 +- ssucli/ssucli.h | 2 +- ssuks/ssukickstarter.cpp | 6 +-- ssuks/ssukickstarter.h | 6 +-- ssuurlresolver/ssuurlresolver.cpp | 4 +- ssuurlresolver/ssuurlresolver.h | 4 +- 22 files changed, 131 insertions(+), 128 deletions(-) diff --git a/declarative/declarativessudeviceinfo.cpp b/declarative/declarativessudeviceinfo.cpp index 23c49f5..1c61fb3 100644 --- a/declarative/declarativessudeviceinfo.cpp +++ b/declarative/declarativessudeviceinfo.cpp @@ -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); } diff --git a/declarative/declarativessudeviceinfo.h b/declarative/declarativessudeviceinfo.h index a007db4..ed2e776 100644 --- a/declarative/declarativessudeviceinfo.h +++ b/declarative/declarativessudeviceinfo.h @@ -55,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; diff --git a/libssu/ssu.cpp b/libssu/ssu.cpp index 74c9cdb..80c65a3 100644 --- a/libssu/ssu.cpp +++ b/libssu/ssu.cpp @@ -76,13 +76,13 @@ Ssu::Ssu() // FIXME, the whole credentials stuff needs reworking // should probably be part of repo handling instead of core configuration -QPair Ssu::credentials(QString scope) +QPair 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); @@ -125,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); @@ -179,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); @@ -259,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 repoParameters, QHash parametersOverride) { @@ -356,7 +356,7 @@ void Ssu::requestFinished(QNetworkReply *reply) } } -void Ssu::sendRegistration(QString usernameDomain, QString password) +void Ssu::sendRegistration(const QString &usernameDomain, const QString &password) { errorFlag = false; @@ -496,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; @@ -511,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(); diff --git a/libssu/ssu.h b/libssu/ssu.h index 15c4067..2ad61fd 100644 --- a/libssu/ssu.h +++ b/libssu/ssu.h @@ -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 credentials(QString scope); + QPair credentials(const QString &scope); /** * Get the scope for a repository, taking into account different scopes for * release and RnD repositories @@ -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 @@ -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 repoParameters = QHash(), QHash parametersOverride = QHash()); /** @@ -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(); @@ -162,7 +162,7 @@ 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); @@ -170,7 +170,7 @@ private slots: * 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: /** @@ -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 diff --git a/libssu/ssucoreconfig.cpp b/libssu/ssucoreconfig.cpp index 8c4124a..cd1c353 100644 --- a/libssu/ssucoreconfig.cpp +++ b/libssu/ssucoreconfig.cpp @@ -25,7 +25,7 @@ SsuCoreConfig *SsuCoreConfig::instance() return ssuCoreConfig; } -QPair SsuCoreConfig::credentials(QString scope) +QPair SsuCoreConfig::credentials(const QString &scope) { QPair ret; beginGroup("credentials-" + scope); @@ -35,7 +35,7 @@ QPair SsuCoreConfig::credentials(QString scope) return ret; } -QString SsuCoreConfig::credentialsScope(QString repoName, bool rndRepo) +QString SsuCoreConfig::credentialsScope(const QString &repoName, bool rndRepo) { Q_UNUSED(repoName) Q_UNUSED(rndRepo) @@ -46,7 +46,7 @@ QString SsuCoreConfig::credentialsScope(QString repoName, bool rndRepo) return "your-configuration-is-broken-and-does-not-contain-credentials-scope"; } -QString SsuCoreConfig::credentialsUrl(QString scope) +QString SsuCoreConfig::credentialsUrl(const QString &scope) { if (contains("credentials-url-" + scope)) return value("credentials-url-" + scope).toString(); @@ -120,7 +120,7 @@ void SsuCoreConfig::setDeviceMode(Ssu::DeviceModeFlags mode, enum Ssu::EditMode sync(); } -void SsuCoreConfig::setFlavour(QString flavour) +void SsuCoreConfig::setFlavour(const QString &flavour) { setValue("flavour", flavour); // flavour is RnD only, so enable RnD mode @@ -128,7 +128,7 @@ void SsuCoreConfig::setFlavour(QString flavour) sync(); } -void SsuCoreConfig::setRelease(QString release, bool rnd) +void SsuCoreConfig::setRelease(const QString &release, bool rnd) { if (rnd) { setValue("rndRelease", release); @@ -141,11 +141,11 @@ void SsuCoreConfig::setRelease(QString release, bool rnd) sync(); } -void SsuCoreConfig::setDomain(QString domain) +void SsuCoreConfig::setDomain(const QString &domain) { // - in domain messes with default section autodetection, // so change it to : - setValue("domain", domain.replace("-", ":")); + setValue("domain", QString(domain).replace("-", ":")); sync(); } diff --git a/libssu/ssucoreconfig_p.h b/libssu/ssucoreconfig_p.h index 1b92a23..e2f238d 100644 --- a/libssu/ssucoreconfig_p.h +++ b/libssu/ssucoreconfig_p.h @@ -34,7 +34,7 @@ class SsuCoreConfig: public SsuSettings * 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 credentials(QString scope); + QPair credentials(const QString &scope); /** * Get the scope for a repository, taking into account different scopes for * release and RnD repositories @@ -44,11 +44,11 @@ class SsuCoreConfig: public SsuSettings * * @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); /** * Get the current flavour when RnD repositories are used * @return current flavour (usually something like testing, release, ..) @@ -87,15 +87,15 @@ class SsuCoreConfig: public SsuSettings /** * Set the flavour used when resolving RND repositories */ - Q_INVOKABLE void setFlavour(QString flavour); + Q_INVOKABLE void setFlavour(const QString &flavour); /** * Set the release version string for either a release, or a RnD snapshot */ - Q_INVOKABLE void setRelease(QString release, bool rnd = false); + Q_INVOKABLE void setRelease(const QString &release, bool rnd = false); /** * Set the domain string (usually something like nemo, jolla, ..) */ - Q_INVOKABLE void setDomain(QString domain); + Q_INVOKABLE void setDomain(const QString &domain); /** * Return configuration settings regarding ssl verification * @retval true SSL verification must be used; that's the default if not configured diff --git a/libssu/ssudeviceinfo.cpp b/libssu/ssudeviceinfo.cpp index de26fff..a02b182 100644 --- a/libssu/ssudeviceinfo.cpp +++ b/libssu/ssudeviceinfo.cpp @@ -340,7 +340,7 @@ QStringList SsuDeviceInfo::disabledRepos() return result; } -QString SsuDeviceInfo::displayName(const int type) +QString SsuDeviceInfo::displayName(int type) { QString model = deviceModel(); QString variant = deviceVariant(false); @@ -429,25 +429,27 @@ QStringList SsuDeviceInfo::repos(bool rnd, int filter) return result; } -QVariant SsuDeviceInfo::variable(QString section, const QString &key) +QVariant SsuDeviceInfo::variable(const QString §ion, const QString &key) { /// @todo compat-setting as ssudeviceinfo guaranteed to prepend sections with var-; /// SsuVariables does not have this guarantee. Remove from here as well. - if (!section.startsWith("var-")) - section = "var-" + section; + QString varSection(section); + if (!varSection.startsWith("var-")) + varSection = "var-" + varSection; - return SsuVariables::variable(boardMappings, section, key); + return SsuVariables::variable(boardMappings, varSection, key); } -void SsuDeviceInfo::variableSection(QString section, QHash *storageHash) +void SsuDeviceInfo::variableSection(const QString §ion, QHash *storageHash) { - if (!section.startsWith("var-")) - section = "var-" + section; + QString varSection(section); + if (!varSection.startsWith("var-")) + varSection = "var-" + varSection; - SsuVariables::variableSection(boardMappings, section, storageHash); + SsuVariables::variableSection(boardMappings, varSection, storageHash); } -void SsuDeviceInfo::setDeviceModel(QString model) +void SsuDeviceInfo::setDeviceModel(const QString &model) { if (model.isEmpty()) cachedModel.clear(); diff --git a/libssu/ssudeviceinfo.h b/libssu/ssudeviceinfo.h index f6d33d6..8b3ff7a 100644 --- a/libssu/ssudeviceinfo.h +++ b/libssu/ssudeviceinfo.h @@ -22,7 +22,7 @@ class SsuDeviceInfo: public QObject /** * Initialize with device to override autodetection */ - SsuDeviceInfo(QString model = ""); + SsuDeviceInfo(const QString &model = QString()); virtual ~SsuDeviceInfo(); @@ -85,7 +85,8 @@ class SsuDeviceInfo: 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); + /** * Return the complete list of repositories configured for a device. * Depending on the filter options, all repostories (user and board), @@ -97,7 +98,7 @@ class SsuDeviceInfo: public QObject /** * Override device model autodetection */ - Q_INVOKABLE void setDeviceModel(QString model = ""); + Q_INVOKABLE void setDeviceModel(const QString &model = QString()); /** * Return a variable from the given variable section. 'var'- is automatically @@ -105,13 +106,13 @@ class SsuDeviceInfo: public QObject * 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); + QVariant variable(const QString §ion, 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 *storageHash); + void variableSection(const QString §ion, QHash *storageHash); /** * Return a value from an adaptation section. Returns an empty string diff --git a/libssu/ssufeaturemanager.cpp b/libssu/ssufeaturemanager.cpp index 4a58375..6121aa7 100644 --- a/libssu/ssufeaturemanager.cpp +++ b/libssu/ssufeaturemanager.cpp @@ -58,7 +58,7 @@ QStringList SsuFeatureManager::repos(bool rndRepo, int filter) return r; } -QString SsuFeatureManager::url(QString repo, bool rndRepo) +QString SsuFeatureManager::url(const QString &repo, bool rndRepo) { QString repoHeader = QString("repositories-%1/") .arg(rndRepo ? "rnd" : "release"); diff --git a/libssu/ssufeaturemanager.h b/libssu/ssufeaturemanager.h index c9e4544..8495b1f 100644 --- a/libssu/ssufeaturemanager.h +++ b/libssu/ssufeaturemanager.h @@ -22,7 +22,7 @@ class SsuFeatureManager: public QObject public: SsuFeatureManager(); QStringList repos(bool rndRepo, int filter = Ssu::NoFilter); - QString url(QString repo, bool rndRepo); + QString url(const QString &repo, bool rndRepo); private: SsuSettings *featureSettings; diff --git a/libssu/ssulog.cpp b/libssu/ssulog.cpp index 705d8df..bc8bd09 100644 --- a/libssu/ssulog.cpp +++ b/libssu/ssulog.cpp @@ -24,7 +24,7 @@ SsuLog *SsuLog::instance() return ssuLog; } -void SsuLog::print(int priority, QString message) +void SsuLog::print(int priority, const QString &message) { // directly go through qsettings here to avoid recursive invocation // of coreconfig / ssulog diff --git a/libssu/ssulog_p.h b/libssu/ssulog_p.h index 250ba6b..c78193d 100644 --- a/libssu/ssulog_p.h +++ b/libssu/ssulog_p.h @@ -20,7 +20,7 @@ class SsuLog /** * Print a message to systemds journal, or to a text log file, if a fallback is defined */ - void print(int priority, QString message); + void print(int priority, const QString &message); private: SsuLog() {} diff --git a/libssu/ssurepomanager.cpp b/libssu/ssurepomanager.cpp index ebb1e5f..9b246ae 100644 --- a/libssu/ssurepomanager.cpp +++ b/libssu/ssurepomanager.cpp @@ -26,7 +26,7 @@ SsuRepoManager::SsuRepoManager() { } -int SsuRepoManager::add(QString repo, QString repoUrl) +int SsuRepoManager::add(const QString &repo, const QString &repoUrl) { SsuCoreConfig *ssuSettings = SsuCoreConfig::instance(); @@ -55,15 +55,13 @@ int SsuRepoManager::add(QString repo, QString repoUrl) return 0; } -QString SsuRepoManager::caCertificatePath(QString domain) +QString SsuRepoManager::caCertificatePath(const QString &domain) { SsuCoreConfig *settings = SsuCoreConfig::instance(); SsuSettings repoSettings(SSU_REPO_CONFIGURATION, QSettings::IniFormat); - if (domain.isEmpty()) - domain = settings->domain(); - - QString ca = SsuVariables::variable(&repoSettings, domain + "-domain", + QString ca = SsuVariables::variable(&repoSettings, + (domain.isEmpty() ? settings->domain() : domain) + "-domain", "_ca-certificate").toString(); if (!ca.isEmpty()) return ca; @@ -75,7 +73,7 @@ QString SsuRepoManager::caCertificatePath(QString domain) return QString(); } -int SsuRepoManager::disable(QString repo) +int SsuRepoManager::disable(const QString &repo) { SsuCoreConfig *ssuSettings = SsuCoreConfig::instance(); QStringList disabledRepos; @@ -92,7 +90,7 @@ int SsuRepoManager::disable(QString repo) return 0; } -int SsuRepoManager::enable(QString repo) +int SsuRepoManager::enable(const QString &repo) { SsuCoreConfig *ssuSettings = SsuCoreConfig::instance(); QStringList disabledRepos; @@ -109,7 +107,7 @@ int SsuRepoManager::enable(QString repo) return 0; } -int SsuRepoManager::remove(QString repo) +int SsuRepoManager::remove(const QString &repo) { SsuCoreConfig *ssuSettings = SsuCoreConfig::instance(); @@ -389,7 +387,7 @@ QStringList SsuRepoManager::repoVariables(QHash *storageHash, // RND repos have flavour (devel, testing, release), and release (latest, next) // Release repos only have release (latest, next, version number) -QString SsuRepoManager::url(QString repoName, bool rndRepo, +QString SsuRepoManager::url(const QString &repoName, bool rndRepo, QHash repoParameters, QHash parametersOverride) { @@ -410,8 +408,7 @@ QString SsuRepoManager::url(QString repoName, bool rndRepo, repoParameters.insert("deviceFamily", deviceInfo.deviceFamily()); repoParameters.insert("deviceModel", deviceInfo.deviceModel()); - repoName = deviceInfo.adaptationVariables(repoName, &repoParameters); - + QString adaptationRepoName = deviceInfo.adaptationVariables(repoName, &repoParameters); SsuCoreConfig *settings = SsuCoreConfig::instance(); QString domain; @@ -443,15 +440,15 @@ QString SsuRepoManager::url(QString repoName, bool rndRepo, SsuFeatureManager featureManager; QString r; - if (settings->contains("repository-urls/" + repoName)) - r = settings->value("repository-urls/" + repoName).toString(); - else if (featureManager.url(repoName, rndRepo) != "") - r = featureManager.url(repoName, rndRepo); - else { + if (settings->contains("repository-urls/" + adaptationRepoName)) { + r = settings->value("repository-urls/" + adaptationRepoName).toString(); + } else if (!featureManager.url(adaptationRepoName, rndRepo).isEmpty()) { + r = featureManager.url(adaptationRepoName, rndRepo); + } else { foreach (const QString §ion, configSections) { repoSettings.beginGroup(section); - if (repoSettings.contains(repoName)) { - r = repoSettings.value(repoName).toString(); + if (repoSettings.contains(adaptationRepoName)) { + r = repoSettings.value(adaptationRepoName).toString(); repoSettings.endGroup(); break; } diff --git a/libssu/ssurepomanager.h b/libssu/ssurepomanager.h index 064fe0e..5ef448d 100644 --- a/libssu/ssurepomanager.h +++ b/libssu/ssurepomanager.h @@ -29,7 +29,7 @@ class SsuRepoManager: public QObject * * If the device is in UpdateMode this function does nothing. */ - int add(QString repo, QString repoUrl = ""); + int add(const QString &repo, const QString &repoUrl = QString()); /** * Return the path to the CA certificate to be used for the given domain, * or default domain, if omitted @@ -38,7 +38,7 @@ class SsuRepoManager: public QObject * @retval -1 Repository not added because device is in update mode * @retval -2 Repository not added because third party repositories are disabled */ - static QString caCertificatePath(QString domain = ""); + static QString caCertificatePath(const QString &domain = QString()); /** * Disable a repository * @@ -46,7 +46,7 @@ class SsuRepoManager: public QObject * @retval -1 Request ignored because device is in update mode * @retval -2 Request ignored because 3rd party repositories are disabled */ - int disable(QString repo); + int disable(const QString &repo); /** * Enable a repository, given it's not disabled by board configuration * @@ -54,7 +54,7 @@ class SsuRepoManager: public QObject * @retval -1 Request ignored because device is in update mode * @retval -2 Request ignored because 3rd party repositories are disabled */ - int enable(QString repo); + int enable(const QString &repo); /** * Remove a repository * @@ -62,7 +62,7 @@ class SsuRepoManager: public QObject * @retval -1 Request ignored because device is in update mode * @retval -2 Request ignored because 3rd party repositories are disabled */ - int remove(QString repo); + int remove(const QString &repo); /** * Collect the list of repositories from different submodules */ @@ -94,7 +94,7 @@ class SsuRepoManager: public QObject * Resolve a repository url * @return the repository URL on success, an empty string on error */ - QString url(QString repoName, bool rndRepo = false, + QString url(const QString &repoName, bool rndRepo = false, QHash repoParameters = QHash(), QHash parametersOverride = QHash()); diff --git a/libssu/ssuvariables.cpp b/libssu/ssuvariables.cpp index cd98a38..1b763c7 100644 --- a/libssu/ssuvariables.cpp +++ b/libssu/ssuvariables.cpp @@ -19,7 +19,7 @@ SsuVariables::SsuVariables() { } -QString SsuVariables::defaultSection(SsuSettings *settings, QString section) +QString SsuVariables::defaultSection(SsuSettings *settings, const QString §ion) { QStringList parts = section.split("-"); @@ -36,7 +36,7 @@ QString SsuVariables::defaultSection(SsuSettings *settings, QString section) return QString(); } -QString SsuVariables::resolveString(QString pattern, QHash *variables, int recursionDepth) +QString SsuVariables::resolveString(const QString &pattern, QHash *variables, int recursionDepth) { if (recursionDepth >= SSU_MAX_RECURSION) { return "maximum-recursion-level-reached"; @@ -46,13 +46,15 @@ QString SsuVariables::resolveString(QString pattern, QHash *va regex.setMinimal(true); int pos = 0; - while ((pos = regex.indexIn(pattern, pos)) != -1) { + QString result(pattern); + + while ((pos = regex.indexIn(result, pos)) != -1) { QString match = regex.cap(0); if (match.contains(":")) { // variable is special, resolve before replacing QString variable = resolveVariable(match, variables); - pattern.replace(match, variable); + result.replace(match, variable); pos += variable.length(); } else { // look up variable name in hashmap, and replace it with stored value, @@ -61,37 +63,39 @@ QString SsuVariables::resolveString(QString pattern, QHash *va variableName.remove(0, 2); variableName.chop(1); if (variables->contains(variableName)) { - pattern.replace(match, variables->value(variableName)); + result.replace(match, variables->value(variableName)); pos += variables->value(variableName).length(); - } else - pattern.replace(match, ""); + } else { + result.replace(match, ""); + } } } // check if string still contains variables, and recurse - if (regex.indexIn(pattern, 0) != -1) - pattern = resolveString(pattern, variables, recursionDepth + 1); + if (regex.indexIn(result, 0) != -1) + result = resolveString(result, variables, recursionDepth + 1); - return pattern; + return result; } -QString SsuVariables::resolveVariable(QString variable, QHash *variables) +QString SsuVariables::resolveVariable(const QString &variable, QHash *variables) { QString variableValue; + QString filteredVariable(variable); - if (variable.endsWith(")")) - variable.chop(1); - if (variable.startsWith("%(")) - variable.remove(0, 2); + if (filteredVariable.endsWith(")")) + filteredVariable.chop(1); + if (filteredVariable.startsWith("%(")) + filteredVariable.remove(0, 2); // hunt for your colon - int magic = variable.indexOf(":"); + int magic = filteredVariable.indexOf(":"); // seems you misplaced your colon - if (magic == -1) return variable; + if (magic == -1) return filteredVariable; - QStringRef variableName(&variable, 0, magic); - QStringRef variableSub(&variable, magic + 2, variable.length() - magic - 2); + QStringRef variableName(&filteredVariable, 0, magic); + QStringRef variableSub(&filteredVariable, magic + 2, filteredVariable.length() - magic - 2); // Fill in variable value for later tests, if it exists if (variables->contains(variableName.toString())) @@ -99,8 +103,8 @@ QString SsuVariables::resolveVariable(QString variable, QHash // find the operator who's after your colon QChar op; - if (variable.length() > magic + 1) - op = variable.at(magic + 1); + if (filteredVariable.length() > magic + 1) + op = filteredVariable.at(magic + 1); switch (op.toLatin1()) { case '-': @@ -143,7 +147,7 @@ SsuSettings *SsuVariables::settings() } /// @todo add override capability with an override-section in ssu.ini -QVariant SsuVariables::variable(QString section, const QString &key) +QVariant SsuVariables::variable(const QString §ion, const QString &key) { if (m_settings != NULL) return variable(m_settings, section, key); @@ -151,7 +155,7 @@ QVariant SsuVariables::variable(QString section, const QString &key) return QVariant(); } -QVariant SsuVariables::variable(SsuSettings *settings, QString section, const QString &key) +QVariant SsuVariables::variable(SsuSettings *settings, const QString §ion, const QString &key) { QVariant value = readVariable(settings, section, key, 0); @@ -166,15 +170,14 @@ QVariant SsuVariables::variable(SsuSettings *settings, QString section, const QS return value; } -void SsuVariables::variableSection(QString section, QHash *storageHash) +void SsuVariables::variableSection(const QString §ion, QHash *storageHash) { if (m_settings != NULL) variableSection(m_settings, section, storageHash); } -void SsuVariables::variableSection(SsuSettings *settings, QString section, QHash *storageHash) +void SsuVariables::variableSection(SsuSettings *settings, const QString §ion, QHash *storageHash) { - QString dSection = defaultSection(settings, section); if (dSection.isEmpty()) { readSection(settings, section, storageHash, 0); @@ -188,7 +191,7 @@ void SsuVariables::variableSection(SsuSettings *settings, QString section, QHash // variables which exist in more than one section will get overwritten when discovered // again // the section itself gets evaluated at the end, again having a chance to overwrite variables -void SsuVariables::readSection(SsuSettings *settings, QString section, +void SsuVariables::readSection(SsuSettings *settings, const QString §ion, QHash *storageHash, int recursionDepth, bool logOverride) { @@ -248,7 +251,7 @@ void SsuVariables::readSection(SsuSettings *settings, QString section, settings->endGroup(); } -QVariant SsuVariables::readVariable(SsuSettings *settings, QString section, const QString &key, +QVariant SsuVariables::readVariable(SsuSettings *settings, const QString §ion, const QString &key, int recursionDepth, bool logOverride) { Q_UNUSED(logOverride) diff --git a/libssu/ssuvariables_p.h b/libssu/ssuvariables_p.h index 5a9c92e..7f68d6e 100644 --- a/libssu/ssuvariables_p.h +++ b/libssu/ssuvariables_p.h @@ -26,15 +26,15 @@ class SsuVariables: public QObject * the first token (or second token for "var-" sections) replaced with * "default". You should therefore avoid "-" in section names. */ - static QString defaultSection(SsuSettings *settings, QString section); + static QString defaultSection(SsuSettings *settings, const QString §ion); /** * Resolve a whole string, containing several variables. Variables inside variables are allowed */ - static QString resolveString(QString pattern, QHash *variables, int recursionDepth = 0); + static QString resolveString(const QString &pattern, QHash *variables, int recursionDepth = 0); /** * Resolve variables; variable can be passed as %(var) or var */ - static QString resolveVariable(QString variable, QHash *variables); + static QString resolveVariable(const QString &variable, QHash *variables); /** * Set the settings object to use */ @@ -49,8 +49,8 @@ class SsuVariables: public QObject * through several variable sections (specified in the section) is supported, * returned will be the last occurence of the variable. */ - QVariant variable(QString section, const QString &key); - static QVariant variable(SsuSettings *settings, QString section, const QString &key); + QVariant variable(const QString §ion, const QString &key); + static QVariant variable(SsuSettings *settings, const QString §ion, const QString &key); /** * Return the requested variable section, recursively looking up all variable * sections referenced inside with the 'variable' keyword. 'var-' is automatically @@ -64,15 +64,15 @@ class SsuVariables: public QObject * This function tries to identify a default configuration section, and merges * the default section with the requested section. */ - void variableSection(QString section, QHash *storageHash); - static void variableSection(SsuSettings *settings, QString section, + void variableSection(const QString §ion, QHash *storageHash); + static void variableSection(SsuSettings *settings, const QString §ion, QHash *storageHash); private: - static void readSection(SsuSettings *settings, QString section, + static void readSection(SsuSettings *settings, const QString §ion, QHash *storageHash, int recursionDepth, bool logOverride = true); - static QVariant readVariable(SsuSettings *settings, QString section, const QString &key, + static QVariant readVariable(SsuSettings *settings, const QString §ion, const QString &key, int recursionDepth, bool logOverride = true); SsuSettings *m_settings; }; diff --git a/ssucli/ssucli.cpp b/ssucli/ssucli.cpp index 2ce5b0f..23cf14e 100644 --- a/ssucli/ssucli.cpp +++ b/ssucli/ssucli.cpp @@ -691,7 +691,7 @@ void SsuCli::uidWarning() } } -void SsuCli::usage(QString message) +void SsuCli::usage(const QString &message) { QTextStream qout(stderr); qout << "\nUsage: ssu [-command-options] [arguments]" << endl diff --git a/ssucli/ssucli.h b/ssucli/ssucli.h index 14149e8..924557a 100644 --- a/ssucli/ssucli.h +++ b/ssucli/ssucli.h @@ -32,7 +32,7 @@ public slots: SsuProxy *ssuProxy; QSettings settings; int state; - void usage(QString message = ""); + void usage(const QString &message = QString()); void uidWarning(); void optDomain(QStringList opt); void optFlavour(QStringList opt); diff --git a/ssuks/ssukickstarter.cpp b/ssuks/ssukickstarter.cpp index 2ea7656..37fee75 100644 --- a/ssuks/ssukickstarter.cpp +++ b/ssuks/ssukickstarter.cpp @@ -144,7 +144,7 @@ QStringList SsuKickstarter::repos() return result; } -QStringList SsuKickstarter::packagesSection(QString name) +QStringList SsuKickstarter::packagesSection(const QString &name) { QStringList result; @@ -167,7 +167,7 @@ QStringList SsuKickstarter::packagesSection(QString name) } // we intentionally don't support device-specific post scriptlets -QStringList SsuKickstarter::scriptletSection(QString name, int flags) +QStringList SsuKickstarter::scriptletSection(const QString &name, int flags) { QStringList result; QString path; @@ -227,7 +227,7 @@ void SsuKickstarter::setRepoParameters(QHash parameters) deviceModel = repoOverride.value("model"); } -bool SsuKickstarter::write(QString kickstart) +bool SsuKickstarter::write(const QString &kickstart) { QTextStream qerr(stderr); QStringList commandSections; diff --git a/ssuks/ssukickstarter.h b/ssuks/ssukickstarter.h index 9814814..09bfde9 100644 --- a/ssuks/ssukickstarter.h +++ b/ssuks/ssukickstarter.h @@ -20,7 +20,7 @@ class SsuKickstarter public: SsuKickstarter(); void setRepoParameters(QHash parameters); - bool write(QString kickstart = ""); + bool write(const QString &kickstart = QString()); enum ScriptletFlags { /// Chroot is not useful, but helps in making the code more readable @@ -37,10 +37,10 @@ class SsuKickstarter QStringList commands(); /// read a command section from file system QStringList commandSection(const QString §ion, const QString &description = QString()); - QStringList packagesSection(QString name); + QStringList packagesSection(const QString &name); QString replaceSpaces(const QString &value); QStringList repos(); - QStringList scriptletSection(QString name, int flags = Chroot); + QStringList scriptletSection(const QString &name, int flags = Chroot); }; #endif diff --git a/ssuurlresolver/ssuurlresolver.cpp b/ssuurlresolver/ssuurlresolver.cpp index bd02644..e2f55f8 100644 --- a/ssuurlresolver/ssuurlresolver.cpp +++ b/ssuurlresolver/ssuurlresolver.cpp @@ -24,7 +24,7 @@ SsuUrlResolver::SsuUrlResolver() Qt::QueuedConnection); } -void SsuUrlResolver::error(QString message) +void SsuUrlResolver::error(const QString &message) { SsuLog *ssuLog = SsuLog::instance(); ssuLog->print(LOG_WARNING, message); @@ -35,7 +35,7 @@ void SsuUrlResolver::error(QString message) QCoreApplication::exit(1); } -bool SsuUrlResolver::writeZyppCredentialsIfNeeded(QString credentialsScope) +bool SsuUrlResolver::writeZyppCredentialsIfNeeded(const QString &credentialsScope) { QString filePath = Sandbox::map("/etc/zypp/credentials.d/" + credentialsScope); QFileInfo credentialsFileInfo(filePath); diff --git a/ssuurlresolver/ssuurlresolver.h b/ssuurlresolver/ssuurlresolver.h index 1145d40..fee5f96 100644 --- a/ssuurlresolver/ssuurlresolver.h +++ b/ssuurlresolver/ssuurlresolver.h @@ -58,8 +58,8 @@ class SsuUrlResolver: public QObject private: Ssu ssu; - void error(QString message); - bool writeZyppCredentialsIfNeeded(QString credentialsScope); + void error(const QString &message); + bool writeZyppCredentialsIfNeeded(const QString &credentialsScope); public slots: void run();