Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Run astyle for Qt coding conventions
Parameters from
https://wiki.qt.io/Qt_Coding_Style#Artistic_Style
except line length to 120
  • Loading branch information
pvuorela committed Oct 10, 2016
1 parent a470b9b commit 52ee9e2
Show file tree
Hide file tree
Showing 71 changed files with 601 additions and 295 deletions.
Whitespace-only changes.
33 changes: 22 additions & 11 deletions libssu/sandbox.cpp
Expand Up @@ -58,19 +58,22 @@ Sandbox *Sandbox::s_activeInstance = 0;
Sandbox::Sandbox()
: m_defaultConstructed(true), m_usage(UseDirectly), m_scopes(ThisProcess),
m_sandboxPath(QProcessEnvironment::systemEnvironment().value("SSU_SANDBOX_DIR")),
m_prepared(false){
m_prepared(false)
{
if (!activate()) {
qFatal("%s: Failed to activate", Q_FUNC_INFO);
}
}

Sandbox::Sandbox(const QString &sandboxPath, Usage usage, Scopes scopes)
: m_defaultConstructed(false), m_usage(usage), m_scopes(scopes),
m_sandboxPath(sandboxPath), m_prepared(false){
m_sandboxPath(sandboxPath), m_prepared(false)
{
Q_ASSERT(!sandboxPath.isEmpty());
}

Sandbox::~Sandbox(){
Sandbox::~Sandbox()
{
if (isActive()) {
deactivate();
}
Expand All @@ -82,11 +85,13 @@ Sandbox::~Sandbox(){
}
}

bool Sandbox::isActive() const{
bool Sandbox::isActive() const
{
return s_activeInstance == this;
}

bool Sandbox::activate(){
bool Sandbox::activate()
{
Q_ASSERT_X(s_activeInstance == 0, Q_FUNC_INFO, "Only one instance can be active!");

if (!prepare()) {
Expand All @@ -101,7 +106,8 @@ bool Sandbox::activate(){
return true;
}

void Sandbox::deactivate(){
void Sandbox::deactivate()
{
Q_ASSERT(isActive());

if (m_scopes & ChildProcesses) {
Expand Down Expand Up @@ -138,7 +144,8 @@ QString Sandbox::map(const QString &pathName, const QString &fileName)
* @c QDir::NoDotAndDotDot is always added into @a filters.
*/
bool Sandbox::addWorldFiles(const QString &directory, QDir::Filters filters,
const QStringList &filterNames, bool recurse){
const QStringList &filterNames, bool recurse)
{
Q_ASSERT(!isActive());
Q_ASSERT(!directory.isEmpty());

Expand Down Expand Up @@ -217,12 +224,14 @@ bool Sandbox::addWorldFiles(const QString &directory, QDir::Filters filters,
return true;
}

bool Sandbox::addWorldFile(const QString &file){
bool Sandbox::addWorldFile(const QString &file)
{
return addWorldFiles(QFileInfo(file).path(), QDir::NoFilter,
QStringList() << QFileInfo(file).fileName());
}

bool Sandbox::prepare(){
bool Sandbox::prepare()
{
Q_ASSERT(m_defaultConstructed || !m_sandboxPath.isEmpty());

if (m_prepared) {
Expand Down Expand Up @@ -265,7 +274,8 @@ bool Sandbox::prepare(){
return true;
}

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

for (int i = 0; i < REASONABLE_REPEAT_COUNT; ++i) {
Expand All @@ -284,7 +294,8 @@ QString Sandbox::createTmpDir(const QString &nameTemplate){
return QString();
}

bool Sandbox::copyDir(const QString &directory, const QString &newName){
bool Sandbox::copyDir(const QString &directory, const QString &newName)
{
const QDir sourceRoot(directory);
const QDir destinationRoot(newName);

Expand Down
3 changes: 2 additions & 1 deletion libssu/sandbox_p.h
Expand Up @@ -18,7 +18,8 @@
getenv("SSU_TESTS_DATA_PATH") : \
TESTS_DATA_PATH)

class Sandbox {
class Sandbox
{
public:
enum Usage {
UseDirectly,
Expand Down
87 changes: 58 additions & 29 deletions libssu/ssu.cpp
Expand Up @@ -32,14 +32,16 @@

#define SSU_NETWORK_REQUEST_DOMAIN_DATA (static_cast<QNetworkRequest::Attribute>(QNetworkRequest::User + 1))

static void restoreUid(){
static void restoreUid()
{
if (getuid() == 0) {
seteuid(0);
setegid(0);
}
}

Ssu::Ssu(): QObject(){
Ssu::Ssu(): QObject()
{
errorFlag = false;
pendingRequests = 0;

Expand Down Expand Up @@ -76,12 +78,14 @@ 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(QString scope)
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
return settings->credentials(scope);
}

QString Ssu::credentialsScope(QString repoName, bool rndRepo){
QString Ssu::credentialsScope(QString repoName, bool rndRepo)
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
SsuSettings repoSettings(SSU_REPO_CONFIGURATION, QSettings::IniFormat);

Expand Down Expand Up @@ -123,67 +127,80 @@ QString Ssu::credentialsScope(QString repoName, bool rndRepo){
return settings->credentialsScope(repoName, rndRepo);
}

QString Ssu::credentialsUrl(QString scope){
QString Ssu::credentialsUrl(QString scope)
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
return settings->credentialsUrl(scope);
}

bool Ssu::error(){
bool Ssu::error()
{
return errorFlag;
}

// Wrappers around SsuCoreConfig
QString Ssu::flavour(){
QString Ssu::flavour()
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
return settings->flavour();
}

Ssu::DeviceModeFlags Ssu::deviceMode(){
Ssu::DeviceModeFlags Ssu::deviceMode()
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
return settings->deviceMode();
}

QString Ssu::domain(){
QString Ssu::domain()
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
return settings->domain(true);
}

bool Ssu::isRegistered(){
bool Ssu::isRegistered()
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
return settings->isRegistered();
}

QDateTime Ssu::lastCredentialsUpdate(){
QDateTime Ssu::lastCredentialsUpdate()
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
return settings->lastCredentialsUpdate();
}

QString Ssu::release(bool rnd){
QString Ssu::release(bool rnd)
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
return settings->release(rnd);
}

void Ssu::setDeviceMode(Ssu::DeviceModeFlags mode, enum Ssu::EditMode editMode){
void Ssu::setDeviceMode(Ssu::DeviceModeFlags mode, enum Ssu::EditMode editMode)
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
settings->setDeviceMode(mode, editMode);
}

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

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

void Ssu::setDomain(QString domain){
void Ssu::setDomain(QString domain)
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
settings->setDomain(domain);
}

bool Ssu::useSslVerify(){
bool Ssu::useSslVerify()
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
return settings->useSslVerify();
}
Expand All @@ -192,11 +209,13 @@ bool Ssu::useSslVerify(){



QString Ssu::lastError(){
QString Ssu::lastError()
{
return errorString;
}

bool Ssu::registerDevice(QDomDocument *response){
bool Ssu::registerDevice(QDomDocument *response)
{
QString certificateString = response->elementsByTagName("certificate").at(0).toElement().text();
QSslCertificate certificate(certificateString.toLatin1());
SsuLog *ssuLog = SsuLog::instance();
Expand Down Expand Up @@ -242,12 +261,14 @@ bool Ssu::registerDevice(QDomDocument *response){
// Release repos only have release (latest, next, version number)
QString Ssu::repoUrl(QString repoName, bool rndRepo,
QHash<QString, QString> repoParameters,
QHash<QString, QString> parametersOverride){
QHash<QString, QString> parametersOverride)
{
SsuRepoManager manager;
return manager.url(repoName, rndRepo, repoParameters, parametersOverride);
}

void Ssu::requestFinished(QNetworkReply *reply){
void Ssu::requestFinished(QNetworkReply *reply)
{
QSslConfiguration sslConfiguration = reply->sslConfiguration();
SsuLog *ssuLog = SsuLog::instance();
SsuCoreConfig *settings = SsuCoreConfig::instance();
Expand Down Expand Up @@ -345,7 +366,8 @@ void Ssu::requestFinished(QNetworkReply *reply){
}
}

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

QString ssuCaCertificate, ssuRegisterUrl;
Expand Down Expand Up @@ -452,7 +474,8 @@ void Ssu::sendRegistration(QString usernameDomain, QString password){
}
}

bool Ssu::setCredentials(QDomDocument *response){
bool Ssu::setCredentials(QDomDocument *response)
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
// generate list with all scopes for generic section, add sections
QDomNodeList credentialsList = response->elementsByTagName("credentials");
Expand Down Expand Up @@ -496,7 +519,8 @@ bool Ssu::setCredentials(QDomDocument *response){
return true;
}

void Ssu::setError(QString errorMessage){
void Ssu::setError(QString errorMessage)
{
errorFlag = true;
errorString = errorMessage;

Expand All @@ -510,7 +534,8 @@ void Ssu::setError(QString errorMessage){
emit done();
}

void Ssu::storeAuthorizedKeys(QByteArray data){
void Ssu::storeAuthorizedKeys(QByteArray data)
{
QDir dir;
SsuLog *ssuLog = SsuLog::instance();

Expand Down Expand Up @@ -571,7 +596,8 @@ void Ssu::storeAuthorizedKeys(QByteArray data){
restoreUid();
}

void Ssu::updateCredentials(bool force){
void Ssu::updateCredentials(bool force)
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
SsuDeviceInfo deviceInfo;
errorFlag = false;
Expand Down Expand Up @@ -645,7 +671,8 @@ void Ssu::updateCredentials(bool force){
manager->get(request);
}

void Ssu::updateStoreCredentials(){
void Ssu::updateStoreCredentials()
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
SsuLog *ssuLog = SsuLog::instance();

Expand All @@ -671,7 +698,8 @@ void Ssu::updateStoreCredentials(){
}
}

void Ssu::unregister(){
void Ssu::unregister()
{
SsuCoreConfig *settings = SsuCoreConfig::instance();
settings->setValue("privateKey", "");
settings->setValue("certificate", "");
Expand All @@ -680,7 +708,8 @@ void Ssu::unregister(){
emit registrationStatusChanged();
}

bool Ssu::verifyResponse(QDomDocument *response){
bool Ssu::verifyResponse(QDomDocument *response)
{
QString action = response->elementsByTagName("action").at(0).toElement().text();
QString deviceId = response->elementsByTagName("deviceId").at(0).toElement().text();
QString protocolVersion = response->elementsByTagName("protocolVersion").at(0).toElement().text();
Expand Down
3 changes: 2 additions & 1 deletion libssu/ssu.h
Expand Up @@ -16,7 +16,8 @@ class QNetworkAccessManager;
class QNetworkReply;
class QDomDocument;

class Ssu: public QObject {
class Ssu: public QObject
{
Q_OBJECT

friend class UrlResolverTest;
Expand Down

0 comments on commit 52ee9e2

Please sign in to comment.