mirror of
https://github.com/arcan1s/queued.git
synced 2025-04-24 15:37:19 +00:00
code cleanup
This commit is contained in:
parent
cdb05844ae
commit
49299af761
@ -1,8 +1,6 @@
|
||||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
# some fucking magic
|
||||
cmake_policy(SET CMP0003 OLD)
|
||||
cmake_policy(SET CMP0002 OLD)
|
||||
cmake_policy(SET CMP0011 NEW)
|
||||
cmake_policy(SET CMP0015 NEW)
|
||||
if (POLICY CMP0063)
|
||||
@ -37,35 +35,13 @@ option(BUILD_FUTURE "Build with the features which will be marked as stable late
|
||||
option(BUILD_LOAD "Build with additional load" OFF)
|
||||
option(BUILD_TESTING "Build with additional test abilities" OFF)
|
||||
|
||||
# flags
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "-Wall -Wno-cpp -std=c++11")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_OPTIMIZATION "-Ofast -DNDEBUG")
|
||||
# avoid newer gcc warnings
|
||||
add_definitions(-D_DEFAULT_SOURCE)
|
||||
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
set(CMAKE_CXX_FLAGS "-Wall -std=c++11 -stdlib=libc++")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_OPTIMIZATION "-Ofast -DNDEBUG")
|
||||
# linker flags
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-lc++abi")
|
||||
set(CMAKE_MODULE_LINKER_FLAGS "-lc++abi")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "-lc++abi")
|
||||
else ()
|
||||
message(FATAL_ERROR "Unknown compiler")
|
||||
endif ()
|
||||
if (CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
endif ()
|
||||
|
||||
set(PROJECT_TRDPARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty)
|
||||
|
||||
set(PROJECT_LIBRARY "queued")
|
||||
set(PROJECT_LIBRARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_LIBRARY}")
|
||||
|
||||
include(compiler.cmake)
|
||||
include(libraries.cmake)
|
||||
include(clang-format.cmake)
|
||||
include(cppcheck.cmake)
|
||||
|
29
sources/compiler.cmake
Normal file
29
sources/compiler.cmake
Normal file
@ -0,0 +1,29 @@
|
||||
# flags
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "-Wall")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_OPTIMIZATION "-Ofast -DNDEBUG")
|
||||
# avoid newer gcc warnings
|
||||
add_definitions(-D_DEFAULT_SOURCE)
|
||||
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
set(CMAKE_CXX_FLAGS "-Wall")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_OPTIMIZATION "-Ofast -DNDEBUG")
|
||||
# linker flags
|
||||
else ()
|
||||
message(FATAL_ERROR "Unknown compiler")
|
||||
endif ()
|
||||
|
||||
# some flags
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# verbose output for debug builds
|
||||
if (CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
endif ()
|
||||
|
||||
# required by successfully coverity and cppcheck build
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
@ -30,6 +30,8 @@ QueuedApplication::QueuedApplication(QObject *parent, const QVariantHash &args)
|
||||
{
|
||||
qCDebug(LOG_APP) << __PRETTY_FUNCTION__;
|
||||
|
||||
m_core = new QueuedCore(this);
|
||||
|
||||
init();
|
||||
initDBus();
|
||||
}
|
||||
@ -41,30 +43,13 @@ QueuedApplication::~QueuedApplication()
|
||||
|
||||
QDBusConnection::sessionBus().unregisterObject(
|
||||
QueuedConfig::DBUS_APPLICATION_PATH);
|
||||
deinit();
|
||||
}
|
||||
|
||||
|
||||
void QueuedApplication::deinit()
|
||||
{
|
||||
if (m_core)
|
||||
delete m_core;
|
||||
m_core->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
void QueuedApplication::init()
|
||||
{
|
||||
deinit();
|
||||
|
||||
initCore();
|
||||
}
|
||||
|
||||
|
||||
void QueuedApplication::initCore()
|
||||
{
|
||||
m_core = new QueuedCore(this);
|
||||
// init objects
|
||||
m_core->init(m_configuration[QString("config")].toString());
|
||||
m_core->init(m_configuration["config"].toString());
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,13 +30,11 @@ class QueuedApplication : public QObject
|
||||
public:
|
||||
explicit QueuedApplication(QObject *parent, const QVariantHash &args);
|
||||
virtual ~QueuedApplication();
|
||||
void deinit();
|
||||
void init();
|
||||
|
||||
private:
|
||||
// backend
|
||||
void initDBus();
|
||||
void initCore();
|
||||
// library
|
||||
QueuedCore *m_core = nullptr;
|
||||
// configuration
|
||||
|
@ -15,19 +15,17 @@
|
||||
|
||||
|
||||
#include <QCommandLineParser>
|
||||
#include <QCoreApplication>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
|
||||
#include <queued/Queued.h>
|
||||
|
||||
#include <csignal>
|
||||
#include <iostream>
|
||||
|
||||
#include "QueuedApplication.h"
|
||||
#include "version.h"
|
||||
|
||||
extern "C" {
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,8 @@ QueuedServer::QueuedServer(QObject *parent, const QVariantHash &args)
|
||||
{
|
||||
qCDebug(LOG_SERV) << __PRETTY_FUNCTION__;
|
||||
|
||||
m_server = new QueuedTcpServer(this);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
@ -35,26 +37,15 @@ QueuedServer::~QueuedServer()
|
||||
{
|
||||
qCDebug(LOG_SERV) << __PRETTY_FUNCTION__;
|
||||
|
||||
deinit();
|
||||
}
|
||||
|
||||
|
||||
void QueuedServer::deinit()
|
||||
{
|
||||
if (m_server)
|
||||
delete m_server;
|
||||
m_server->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
void QueuedServer::init()
|
||||
{
|
||||
deinit();
|
||||
|
||||
m_server
|
||||
= new QueuedTcpServer(QueuedCoreAdaptor::getOption(
|
||||
QueuedConfig::QueuedSettings::ServerTimeout)
|
||||
.toInt(),
|
||||
this);
|
||||
m_server->init(QueuedCoreAdaptor::getOption(
|
||||
QueuedConfig::QueuedSettings::ServerTimeout)
|
||||
.toInt());
|
||||
QString address = QueuedCoreAdaptor::getOption(
|
||||
QueuedConfig::QueuedSettings::ServerAddress)
|
||||
.toString();
|
||||
|
@ -30,7 +30,6 @@ class QueuedServer : public QObject
|
||||
public:
|
||||
explicit QueuedServer(QObject *parent, const QVariantHash &args);
|
||||
virtual ~QueuedServer();
|
||||
void deinit();
|
||||
void init();
|
||||
|
||||
private:
|
||||
|
@ -21,9 +21,8 @@
|
||||
#include "QueuedTcpServerThread.h"
|
||||
|
||||
|
||||
QueuedTcpServer::QueuedTcpServer(const int timeout, QObject *parent)
|
||||
QueuedTcpServer::QueuedTcpServer(QObject *parent)
|
||||
: QTcpServer(parent)
|
||||
, m_timeout(timeout)
|
||||
{
|
||||
qCDebug(LOG_SERV) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
@ -32,26 +31,18 @@ QueuedTcpServer::QueuedTcpServer(const int timeout, QObject *parent)
|
||||
QueuedTcpServer::~QueuedTcpServer()
|
||||
{
|
||||
qCDebug(LOG_SERV) << __PRETTY_FUNCTION__;
|
||||
|
||||
deinit();
|
||||
}
|
||||
|
||||
|
||||
void QueuedTcpServer::deinit()
|
||||
void QueuedTcpServer::init(const int timeout)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void QueuedTcpServer::init()
|
||||
{
|
||||
deinit();
|
||||
m_timeout = timeout;
|
||||
}
|
||||
|
||||
|
||||
void QueuedTcpServer::incomingConnection(qintptr socketDescriptor)
|
||||
{
|
||||
QueuedTcpServerThread *thread
|
||||
= new QueuedTcpServerThread(socketDescriptor, m_timeout, this);
|
||||
auto thread = new QueuedTcpServerThread(socketDescriptor, m_timeout, this);
|
||||
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
||||
thread->start();
|
||||
}
|
||||
|
@ -25,10 +25,9 @@ class QueuedTcpServer : public QTcpServer
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit QueuedTcpServer(const int timeout, QObject *parent);
|
||||
explicit QueuedTcpServer(QObject *parent);
|
||||
virtual ~QueuedTcpServer();
|
||||
void deinit();
|
||||
void init();
|
||||
void init(const int timeout);
|
||||
|
||||
protected:
|
||||
void incomingConnection(qintptr socketDescriptor) override;
|
||||
|
@ -111,7 +111,6 @@ QVariantHash QueuedTcpServerResponseHelperApi1::getData(
|
||||
else
|
||||
output = {{"code", 405}};
|
||||
break;
|
||||
break;
|
||||
case QueuedTcpServerResponseHelper::RequestPath::User:
|
||||
if (_type == "GET")
|
||||
output = QueuedTcpServerResponseHelperUser::getUser(_arg, _data);
|
||||
|
@ -52,8 +52,9 @@ QVariantHash QueuedTcpServerResponseHelperPermissions::removePermission(
|
||||
if (permission == QueuedEnums::Permission::Invalid)
|
||||
return {{"code", 400}, {"message", "Invalid permission"}};
|
||||
|
||||
return {{"code", QueuedCoreAdaptor::sendUserPermissionRemove(
|
||||
_id, permission, _token)
|
||||
? 200
|
||||
: 400}};
|
||||
return {
|
||||
{"code",
|
||||
QueuedCoreAdaptor::sendUserPermissionRemove(_id, permission, _token)
|
||||
? 200
|
||||
: 400}};
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ QueuedTcpServerResponseHelperTask::getDefinitions(const QVariantHash &_data)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Get definitions from" << _data;
|
||||
|
||||
QueuedProcess::QueuedProcessDefinitions defs;
|
||||
auto defs = QueuedProcess::QueuedProcessDefinitions();
|
||||
auto args = _data["arguments"].toList();
|
||||
for (auto &arg : args)
|
||||
defs.arguments.append(arg.toString());
|
||||
@ -94,7 +94,7 @@ QueuedTcpServerResponseHelperTask::getTasks(const QVariantHash &_data,
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Get tasks" << _data;
|
||||
|
||||
long long user = _data.value("userId").toLongLong();
|
||||
long long userId = _data.value("userId").toLongLong();
|
||||
QDateTime start
|
||||
= QDateTime::fromString(_data["start"].toString(), Qt::ISODateWithMs);
|
||||
QDateTime stop
|
||||
@ -103,7 +103,7 @@ QueuedTcpServerResponseHelperTask::getTasks(const QVariantHash &_data,
|
||||
QVariantHash output = {{"code", 200}};
|
||||
// some conversion magic
|
||||
QVariantList outputReport;
|
||||
auto report = QueuedCoreAdaptor::getTasks(user, start, stop, _token);
|
||||
auto report = QueuedCoreAdaptor::getTasks(userId, start, stop, _token);
|
||||
for (auto &user : report)
|
||||
outputReport.append(user);
|
||||
output["report"] = outputReport;
|
||||
|
@ -82,7 +82,7 @@ QueuedTcpServerThread::getHeaders(const QStringList &headers)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Get headers object from" << headers;
|
||||
|
||||
QueuedTcpServerThread::QueuedTcpServerHeaders headersObj;
|
||||
auto headersObj = QueuedTcpServerThread::QueuedTcpServerHeaders();
|
||||
|
||||
// metadata
|
||||
auto protocolData = headers.first().split(' ');
|
||||
@ -96,8 +96,9 @@ QueuedTcpServerThread::getHeaders(const QStringList &headers)
|
||||
auto parsed = header.split(": ");
|
||||
if (parsed.count() < 2)
|
||||
continue;
|
||||
headersObj.headers += {parsed.first().toUtf8().toLower(),
|
||||
parsed.mid(1).join(": ").toUtf8()};
|
||||
headersObj.headers += QPair<QByteArray, QByteArray>(
|
||||
{parsed.first().toUtf8().toLower(),
|
||||
parsed.mid(1).join(": ").toUtf8()});
|
||||
}
|
||||
|
||||
return headersObj;
|
||||
@ -114,7 +115,7 @@ QueuedTcpServerThread::QueuedTcpServerRequest QueuedTcpServerThread::getRequest(
|
||||
request.headers = headers;
|
||||
|
||||
// body
|
||||
QJsonParseError error;
|
||||
auto error = QJsonParseError();
|
||||
auto jsonDoc = QJsonDocument::fromJson(body, &error);
|
||||
if (error.error == QJsonParseError::NoError)
|
||||
request.data = jsonDoc.object().toVariantHash();
|
||||
|
@ -15,19 +15,17 @@
|
||||
|
||||
|
||||
#include <QCommandLineParser>
|
||||
#include <QCoreApplication>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
|
||||
#include <queued/Queued.h>
|
||||
|
||||
#include <csignal>
|
||||
#include <iostream>
|
||||
|
||||
#include "QueuedServer.h"
|
||||
#include "version.h"
|
||||
|
||||
extern "C" {
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
}
|
||||
|
||||
|
@ -2122,7 +2122,7 @@ HIDE_UNDOC_RELATIONS = YES
|
||||
# set to NO
|
||||
# The default value is: NO.
|
||||
|
||||
HAVE_DOT = NO
|
||||
HAVE_DOT = YES
|
||||
|
||||
# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed
|
||||
# to run in parallel. When set to 0 doxygen will base this on the number of
|
||||
|
@ -216,7 +216,7 @@ QHash<QString, QHash<QString, QString>> getStatus();
|
||||
*/
|
||||
QVariantHash getTask(const long long _id);
|
||||
/**
|
||||
* @return server status inforamtion
|
||||
* @return server status information
|
||||
*/
|
||||
QHash<QString, QHash<QString, QString>> getStatus();
|
||||
/**
|
||||
|
@ -38,12 +38,18 @@ public:
|
||||
* @param message
|
||||
* exception message
|
||||
*/
|
||||
QueuedException(const QString &message)
|
||||
: m_message(message){};
|
||||
explicit QueuedException(QString message)
|
||||
: QException()
|
||||
{
|
||||
m_message = std::move(message);
|
||||
};
|
||||
/**
|
||||
* @brief clone QueuedException
|
||||
*/
|
||||
QueuedException *clone() const { return new QueuedException(*this); };
|
||||
QueuedException *clone() const override
|
||||
{
|
||||
return new QueuedException(*this);
|
||||
};
|
||||
/**
|
||||
* @brief message of this exception
|
||||
* @return message for logging, etc
|
||||
@ -52,7 +58,7 @@ public:
|
||||
/**
|
||||
* @brief raise QueuedException
|
||||
*/
|
||||
void raise() const { throw * this; }
|
||||
void raise() const override { throw * this; }
|
||||
|
||||
private:
|
||||
/**
|
||||
@ -73,7 +79,7 @@ public:
|
||||
* @param message
|
||||
* exception message
|
||||
*/
|
||||
QueuedConfigurationException(const QString &message)
|
||||
explicit QueuedConfigurationException(const QString &message)
|
||||
: QueuedException(message){};
|
||||
};
|
||||
|
||||
@ -89,7 +95,7 @@ public:
|
||||
* @param message
|
||||
* exception message
|
||||
*/
|
||||
QueuedDatabaseException(const QString &message)
|
||||
explicit QueuedDatabaseException(const QString &message)
|
||||
: QueuedException(message){};
|
||||
};
|
||||
|
||||
@ -105,7 +111,7 @@ public:
|
||||
* @param message
|
||||
* exception message
|
||||
*/
|
||||
QueuedDBusException(const QString &message)
|
||||
explicit QueuedDBusException(const QString &message)
|
||||
: QueuedException(message){};
|
||||
};
|
||||
|
||||
|
@ -84,7 +84,8 @@ struct Limits {
|
||||
* @param _stringLimits
|
||||
* limits string representation
|
||||
*/
|
||||
Limits(const QString &_stringLimits)
|
||||
explicit Limits(const QString &_stringLimits)
|
||||
: Limits()
|
||||
{
|
||||
QStringList limits = _stringLimits.split(QChar('\n'));
|
||||
while (limits.count() < 5)
|
||||
|
@ -40,7 +40,7 @@ public:
|
||||
/**
|
||||
* @brief QueuedPluginInterface class destructor
|
||||
*/
|
||||
virtual ~QueuedPluginInterface(){};
|
||||
virtual ~QueuedPluginInterface() = default;
|
||||
/**
|
||||
* @brief will be emitted to map interface signals to plugin slots
|
||||
* @param _manager
|
||||
|
@ -43,7 +43,8 @@ public:
|
||||
/**
|
||||
* @brief QueuedPluginManagerInterface class destructor
|
||||
*/
|
||||
virtual ~QueuedPluginManagerInterface(){};
|
||||
virtual ~QueuedPluginManagerInterface() = default;
|
||||
;
|
||||
|
||||
signals:
|
||||
/**
|
||||
|
@ -53,10 +53,8 @@ bool QueuedAdvancedSettings::checkDatabaseVersion() const
|
||||
{
|
||||
QString key = internalId(QueuedConfig::QueuedSettings::DatabaseVersion);
|
||||
|
||||
if (m_values.contains(key.toLower()))
|
||||
return get(key).toInt() == QueuedConfig::DATABASE_VERSION;
|
||||
else
|
||||
return false;
|
||||
return m_values.contains(key.toLower())
|
||||
&& (get(key).toInt() == QueuedConfig::DATABASE_VERSION);
|
||||
}
|
||||
|
||||
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include <QDBusMessage>
|
||||
|
||||
#include <queued/QueuedDatabaseSchema.h>
|
||||
#include <queued/QueuedStaticConfig.h>
|
||||
|
||||
|
||||
/**
|
||||
@ -233,8 +232,8 @@ bool QueuedCore::editTask(const long long _id, const QVariantHash &_taskData,
|
||||
// only admin can edit run/stopped task
|
||||
if (!task->startTime().isNull()) {
|
||||
if (!isAdmin) {
|
||||
qCInfo(LOG_LIB) << "User" << _token
|
||||
<< "not allowed to edit run/exited task";
|
||||
qCInfo(LOG_LIB)
|
||||
<< "User" << _token << "not allowed to edit run/exited task";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -306,8 +305,8 @@ bool QueuedCore::editUserPermission(const long long _id,
|
||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||
if (userAuthId != _id) {
|
||||
if (!isAdmin) {
|
||||
qCInfo(LOG_LIB) << "User" << _token
|
||||
<< "not allowed to edit permissions";
|
||||
qCInfo(LOG_LIB)
|
||||
<< "User" << _token << "not allowed to edit permissions";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -501,8 +500,8 @@ QList<QVariantHash> QueuedCore::taskReport(const long long _user,
|
||||
effectiveUserId = userAuthId;
|
||||
} else if (userAuthId != _user) {
|
||||
if (!isAdmin) {
|
||||
qCInfo(LOG_LIB) << "User" << _token
|
||||
<< "not allowed to get task report";
|
||||
qCInfo(LOG_LIB)
|
||||
<< "User" << _token << "not allowed to get task report";
|
||||
return QList<QVariantHash>();
|
||||
}
|
||||
}
|
||||
@ -575,22 +574,14 @@ void QueuedCore::deinit()
|
||||
QDBusConnection::sessionBus().unregisterService(QueuedConfig::DBUS_SERVICE);
|
||||
|
||||
// delete objects now
|
||||
if (m_databaseManager)
|
||||
delete m_databaseManager;
|
||||
if (m_reports)
|
||||
delete m_reports;
|
||||
if (m_plugins)
|
||||
delete m_plugins;
|
||||
if (m_processes)
|
||||
delete m_processes;
|
||||
if (m_users)
|
||||
delete m_users;
|
||||
if (m_database)
|
||||
delete m_database;
|
||||
if (m_settings)
|
||||
delete m_settings;
|
||||
if (m_advancedSettings)
|
||||
delete m_advancedSettings;
|
||||
delete m_databaseManager;
|
||||
delete m_reports;
|
||||
delete m_plugins;
|
||||
delete m_processes;
|
||||
delete m_users;
|
||||
delete m_database;
|
||||
delete m_settings;
|
||||
delete m_advancedSettings;
|
||||
}
|
||||
|
||||
|
||||
@ -991,7 +982,7 @@ bool QueuedCore::editOptionPrivate(const QString &_key, const QVariant &_value)
|
||||
long long id = m_advancedSettings->id(_key);
|
||||
QVariantHash payload = {{"key", _key}, {"value", _value}};
|
||||
|
||||
bool status = false;
|
||||
bool status;
|
||||
if (id == -1) {
|
||||
id = m_database->add(QueuedDB::SETTINGS_TABLE, payload);
|
||||
qCInfo(LOG_LIB) << "Added new key with ID" << id;
|
||||
@ -1146,7 +1137,7 @@ bool QueuedCore::editUserPermissionPrivate(
|
||||
// edit runtime permissions to get value
|
||||
auto perms = _add ? userObj->addPermission(_permission)
|
||||
: userObj->removePermission(_permission);
|
||||
uint permissions = static_cast<uint>(perms);
|
||||
auto permissions = static_cast<uint>(perms);
|
||||
qCInfo(LOG_LIB) << "New user permissions" << perms << permissions;
|
||||
|
||||
// modify in database now
|
||||
|
@ -351,9 +351,9 @@ void QueuedDatabase::createSchema(const QString &_table)
|
||||
.arg(field.sqlDescription));
|
||||
QSqlError error = query.lastError();
|
||||
if (error.isValid())
|
||||
qCCritical(LOG_LIB) << "Could not insert column" << column
|
||||
<< "to table" << _table
|
||||
<< "error:" << error.text();
|
||||
qCCritical(LOG_LIB)
|
||||
<< "Could not insert column" << column << "to table" << _table
|
||||
<< "error:" << error.text();
|
||||
}
|
||||
}
|
||||
|
||||
@ -370,8 +370,8 @@ void QueuedDatabase::createTable(const QString &_table)
|
||||
.arg(_table));
|
||||
QSqlError error = query.lastError();
|
||||
if (error.isValid())
|
||||
qCCritical(LOG_LIB) << "Could not create table" << _table
|
||||
<< "error:" << error.text();
|
||||
qCCritical(LOG_LIB)
|
||||
<< "Could not create table" << _table << "error:" << error.text();
|
||||
}
|
||||
|
||||
|
||||
@ -408,7 +408,7 @@ long long QueuedDatabase::lastInsertionId(const QString &_table) const
|
||||
return -1;
|
||||
}
|
||||
|
||||
long long id;
|
||||
long long id = -1;
|
||||
while (query.next())
|
||||
id = query.value(0).toLongLong();
|
||||
|
||||
@ -430,8 +430,8 @@ QueuedDatabase::getQueryPayload(const QString &_table,
|
||||
QStringList schemaColumns = QueuedDB::DBSchema[_table].keys();
|
||||
for (auto &key : _value.keys()) {
|
||||
if (!schemaColumns.contains(key)) {
|
||||
qCWarning(LOG_LIB) << "No key" << key << "found in schema of"
|
||||
<< _table;
|
||||
qCWarning(LOG_LIB)
|
||||
<< "No key" << key << "found in schema of" << _table;
|
||||
continue;
|
||||
}
|
||||
if (key == QString("_id")) {
|
||||
|
@ -23,8 +23,6 @@
|
||||
|
||||
#include <queued/Queued.h>
|
||||
|
||||
#include <QDateTime>
|
||||
|
||||
|
||||
/**
|
||||
* @class QueuedDatabaseManager
|
||||
|
@ -52,10 +52,8 @@ bool QueuedLimits::limitCompare(const long long _first, const long long _second)
|
||||
{
|
||||
if (_first == 0)
|
||||
return false;
|
||||
else if (_second == 0)
|
||||
return true;
|
||||
else
|
||||
return _first < _second;
|
||||
return (_second == 0) || (_first < _second);
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,8 +26,6 @@
|
||||
#include <QMetaProperty>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include <queued/QueuedProcess.h>
|
||||
|
||||
|
||||
/**
|
||||
* @class QueuedProcess
|
||||
@ -82,9 +80,10 @@ void QueuedProcess::updateArguments()
|
||||
|
||||
// replace limits now
|
||||
application.replace(
|
||||
"{cpu}", QString("%1").arg(
|
||||
QueuedSystemInfo::cpuWeight(nativeLimits().cpu) * 100.0, 0,
|
||||
'f', 0));
|
||||
"{cpu}",
|
||||
QString("%1").arg(QueuedSystemInfo::cpuWeight(nativeLimits().cpu)
|
||||
* 100.0,
|
||||
0, 'f', 0));
|
||||
application.replace(
|
||||
"{memory}",
|
||||
QString("%1").arg(QueuedSystemInfo::memoryWeight(nativeLimits().memory)
|
||||
|
@ -102,7 +102,7 @@ QueuedProcess *QueuedProcessManager::add(
|
||||
if (processes().contains(_index))
|
||||
return process(_index);
|
||||
|
||||
QueuedProcess *process = new QueuedProcess(this, _definitions, _index);
|
||||
auto *process = new QueuedProcess(this, _definitions, _index);
|
||||
process->setProcessLine(processLine());
|
||||
m_processes[_index] = process;
|
||||
// connect to signal
|
||||
|
@ -23,9 +23,7 @@
|
||||
|
||||
#include <queued/Queued.h>
|
||||
|
||||
#include <QTimer>
|
||||
#include <QUuid>
|
||||
#include <queued/Queued.h>
|
||||
|
||||
|
||||
/**
|
||||
@ -111,8 +109,7 @@ QString QueuedTokenManager::registerToken(const QString &_user,
|
||||
const QDateTime &_validUntil)
|
||||
{
|
||||
// generate from uuid
|
||||
QString token
|
||||
= QUuid::createUuid().toString().remove(QChar('{')).remove(QChar('}'));
|
||||
QString &token = QUuid::createUuid().toString().remove('{').remove('}');
|
||||
qCInfo(LOG_LIB) << "Registered token" << token << "valid until"
|
||||
<< _validUntil;
|
||||
|
||||
|
@ -92,12 +92,10 @@ bool QueuedUser::hasPermission(const QueuedEnums::Permission _permission)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Check permissions" << static_cast<int>(_permission);
|
||||
|
||||
if (static_cast<QueuedEnums::Permissions>(m_definitions.permissions)
|
||||
.testFlag(QueuedEnums::Permission::SuperAdmin))
|
||||
return true;
|
||||
else
|
||||
return static_cast<QueuedEnums::Permissions>(m_definitions.permissions)
|
||||
.testFlag(_permission);
|
||||
return static_cast<QueuedEnums::Permissions>(m_definitions.permissions)
|
||||
.testFlag(QueuedEnums::Permission::SuperAdmin)
|
||||
|| static_cast<QueuedEnums::Permissions>(m_definitions.permissions)
|
||||
.testFlag(_permission);
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,8 +23,6 @@
|
||||
|
||||
#include <queued/Queued.h>
|
||||
|
||||
#include <QDateTime>
|
||||
|
||||
|
||||
/**
|
||||
* @class QueuedUserManager
|
||||
|
@ -210,7 +210,7 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
||||
qCDebug(LOG_APP) << "Process command with args"
|
||||
<< "using auth" << _cache << _user;
|
||||
|
||||
QueuedctlResult result;
|
||||
auto result = QueuedctlResult();
|
||||
QStringList args = _parser.positionalArguments();
|
||||
QString command = args.isEmpty() ? QString() : args.first();
|
||||
|
||||
@ -316,10 +316,10 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
||||
case QueuedctlArgument::TaskAdd: {
|
||||
QString token = QueuedctlAuth::getToken(_cache, _user);
|
||||
auto definitions = QueuedctlTask::getDefinitions(_parser, false);
|
||||
long long id = QueuedctlTask::addTask(definitions, token);
|
||||
result.status = (id > 0);
|
||||
long long taskId = QueuedctlTask::addTask(definitions, token);
|
||||
result.status = (taskId > 0);
|
||||
if (result.status)
|
||||
result.output = QString("Task %1 added").arg(id);
|
||||
result.output = QString("Task %1 added").arg(taskId);
|
||||
else
|
||||
result.output = QString("Could not add task");
|
||||
break;
|
||||
@ -360,10 +360,10 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
||||
case QueuedctlArgument::UserAdd: {
|
||||
QString token = QueuedctlAuth::getToken(_cache, _user);
|
||||
auto definitions = QueuedctlUser::getDefinitions(_parser, false);
|
||||
long long id = QueuedctlUser::addUser(definitions, token);
|
||||
result.status = (id > 0);
|
||||
long long userId = QueuedctlUser::addUser(definitions, token);
|
||||
result.status = (userId > 0);
|
||||
if (result.status)
|
||||
result.output = QString("User %1 added").arg(id);
|
||||
result.output = QString("User %1 added").arg(userId);
|
||||
else
|
||||
result.output = QString("Could not add user");
|
||||
break;
|
||||
|
@ -27,11 +27,8 @@ bool QueuedctlPermissions::addPermission(const long long _id,
|
||||
|
||||
auto permission = QueuedEnums::stringToPermission(_permission);
|
||||
|
||||
if (permission != QueuedEnums::Permission::Invalid)
|
||||
return QueuedCoreAdaptor::sendUserPermissionAdd(_id, permission,
|
||||
_token);
|
||||
else
|
||||
return false;
|
||||
return (permission != QueuedEnums::Permission::Invalid)
|
||||
&& QueuedCoreAdaptor::sendUserPermissionAdd(_id, permission, _token);
|
||||
}
|
||||
|
||||
|
||||
@ -43,11 +40,9 @@ bool QueuedctlPermissions::removePermission(const long long _id,
|
||||
|
||||
auto permission = QueuedEnums::stringToPermission(_permission);
|
||||
|
||||
if (permission != QueuedEnums::Permission::Invalid)
|
||||
return QueuedCoreAdaptor::sendUserPermissionRemove(_id, permission,
|
||||
_token);
|
||||
else
|
||||
return false;
|
||||
return (permission != QueuedEnums::Permission::Invalid)
|
||||
&& QueuedCoreAdaptor::sendUserPermissionRemove(_id, permission,
|
||||
_token);
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,8 +20,6 @@
|
||||
|
||||
#include <queued/Queued.h>
|
||||
|
||||
#include "QueuedctlUser.h"
|
||||
|
||||
extern "C" {
|
||||
#include <unistd.h>
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ QueuedctlUser::getDefinitions(const QCommandLineParser &_parser,
|
||||
QString QueuedctlUser::getPassword()
|
||||
{
|
||||
// do not show input characters
|
||||
struct termios tty;
|
||||
auto tty = termios();
|
||||
::tcgetattr(STDIN_FILENO, &tty);
|
||||
tty.c_lflag &= ~ECHO;
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &tty);
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
|
||||
#include <QCommandLineParser>
|
||||
#include <QCoreApplication>
|
||||
|
||||
#include <queued/Queued.h>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user