mirror of
https://github.com/arcan1s/queued.git
synced 2025-04-25 07:57:18 +00:00
add token and settigns managers
This commit is contained in:
parent
6ad0731a4a
commit
aa527d2975
@ -24,11 +24,15 @@
|
|||||||
#ifndef QUEUED_H
|
#ifndef QUEUED_H
|
||||||
#define QUEUED_H
|
#define QUEUED_H
|
||||||
|
|
||||||
|
#include "QueuedAdvancedSettings.h"
|
||||||
|
#include "QueuedConfiguration.h"
|
||||||
#include "QueuedDatabase.h"
|
#include "QueuedDatabase.h"
|
||||||
#include "QueuedDebug.h"
|
#include "QueuedDebug.h"
|
||||||
#include "QueuedEnums.h"
|
#include "QueuedEnums.h"
|
||||||
#include "QueuedProcess.h"
|
#include "QueuedProcess.h"
|
||||||
#include "QueuedProcessManager.h"
|
#include "QueuedProcessManager.h"
|
||||||
|
#include "QueuedSettings.h"
|
||||||
|
#include "QueuedTokenManager.h"
|
||||||
#include "QueuedUser.h"
|
#include "QueuedUser.h"
|
||||||
|
|
||||||
#endif /* QUEUED_H */
|
#endif /* QUEUED_H */
|
||||||
|
59
sources/queued/include/queued/QueuedAdvancedSettings.h
Normal file
59
sources/queued/include/queued/QueuedAdvancedSettings.h
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Evgeniy Alekseev
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
*
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file QueuedAdvancedSettings.h
|
||||||
|
* Header of Queued library
|
||||||
|
* @author Evgeniy Alekseev
|
||||||
|
* @copyright MIT
|
||||||
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef QUEUEDADVANCEDSETTINGS_H
|
||||||
|
#define QUEUEDADVANCEDSETTINGS_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#include "QueuedConfiguration.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief implementation over database stored settings
|
||||||
|
*/
|
||||||
|
class QueuedAdvancedSettings : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief QueuedAdvancedSettings class constructor
|
||||||
|
* @param parent pointer to parent item
|
||||||
|
*/
|
||||||
|
explicit QueuedAdvancedSettings(QObject *parent);
|
||||||
|
/**
|
||||||
|
* @brief QueuedAdvancedSettings class destructor
|
||||||
|
*/
|
||||||
|
virtual ~QueuedAdvancedSettings();
|
||||||
|
/**
|
||||||
|
* @brief upload configuration from database in to internal format
|
||||||
|
* @param _value configuration values from database
|
||||||
|
*/
|
||||||
|
void setValues(const QList<QVariantHash> &_values);
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* QUEUEDADVANCEDSETTINGS_H */
|
77
sources/queued/include/queued/QueuedConfiguration.h
Normal file
77
sources/queued/include/queued/QueuedConfiguration.h
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Evgeniy Alekseev
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
*
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file QueuedCOnfiguration.h
|
||||||
|
* Header of Queued library
|
||||||
|
* @author Evgeniy Alekseev
|
||||||
|
* @copyright MIT
|
||||||
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef QUEUEDCONFIGURATION_H
|
||||||
|
#define QUEUEDCONFIGURATION_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup QueuedCfg
|
||||||
|
* @brief Queued configuration related types
|
||||||
|
*/
|
||||||
|
namespace QueuedCfg
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @ingroup QueuedCfg
|
||||||
|
* @struct QueuedAdminSetup
|
||||||
|
* @brief structure to define administrator user
|
||||||
|
* @var name
|
||||||
|
* administrator user name
|
||||||
|
* @var password
|
||||||
|
* administrator user password
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
QString name;
|
||||||
|
QString password;
|
||||||
|
} QueuedAdminSetup;
|
||||||
|
/**
|
||||||
|
* m@ingroup QueuedCfg
|
||||||
|
* @struct QueuedDBSetup
|
||||||
|
* @brief structure to define database setup
|
||||||
|
* @var driver
|
||||||
|
* driver name
|
||||||
|
* @var hostname
|
||||||
|
* hostname to connect
|
||||||
|
* @var password
|
||||||
|
* password to connect if any
|
||||||
|
* @var path
|
||||||
|
* path to database
|
||||||
|
* @var port
|
||||||
|
* port to connect
|
||||||
|
* @var username
|
||||||
|
* username to connect if any
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
QString driver;
|
||||||
|
QString hostname;
|
||||||
|
QString password;
|
||||||
|
QString path;
|
||||||
|
int port;
|
||||||
|
QString username;
|
||||||
|
} QueuedDBSetup;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* QUEUEDCONFIGURATION_H */
|
@ -54,9 +54,9 @@ public:
|
|||||||
* @brief add record to database
|
* @brief add record to database
|
||||||
* @param _table table name
|
* @param _table table name
|
||||||
* @param _value value to insert
|
* @param _value value to insert
|
||||||
* @return true on success
|
* @return index of inserted record or -1 if no insertion
|
||||||
*/
|
*/
|
||||||
bool add(const QString &_table, const QVariantHash &_value);
|
long long add(const QString &_table, const QVariantHash &_value);
|
||||||
/**
|
/**
|
||||||
* @brief check and create database
|
* @brief check and create database
|
||||||
*/
|
*/
|
||||||
@ -132,6 +132,12 @@ private:
|
|||||||
*/
|
*/
|
||||||
QHash<QString, int> getColumnsInRecord(const QStringList &_columns,
|
QHash<QString, int> getColumnsInRecord(const QStringList &_columns,
|
||||||
const QSqlRecord &_record) const;
|
const QSqlRecord &_record) const;
|
||||||
|
/**
|
||||||
|
* @brief last insertion ID
|
||||||
|
* @param _table table name
|
||||||
|
* @return last insertion id from table
|
||||||
|
*/
|
||||||
|
long long lastInsertionId(const QString &_table) const;
|
||||||
/**
|
/**
|
||||||
* @brief additional function to get payload for query
|
* @brief additional function to get payload for query
|
||||||
* @param _table table name for search
|
* @param _table table name for search
|
||||||
@ -142,4 +148,5 @@ private:
|
|||||||
getQueryPayload(const QString &_table, const QVariantHash &_value) const;
|
getQueryPayload(const QString &_table, const QVariantHash &_value) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* QUEUEDDATABASE_H */
|
#endif /* QUEUEDDATABASE_H */
|
||||||
|
@ -28,27 +28,6 @@
|
|||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @struct QueuedDBField
|
|
||||||
* @brief describes database column
|
|
||||||
* @var name
|
|
||||||
* column name
|
|
||||||
* @var sqlDescription
|
|
||||||
* description to create column
|
|
||||||
* @var type
|
|
||||||
* Qt type of column for cast
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
QString name;
|
|
||||||
QString sqlDescription;
|
|
||||||
QVariant::Type type;
|
|
||||||
} QueuedDBField;
|
|
||||||
/**
|
|
||||||
* @typedef QueuedDBSchema
|
|
||||||
* custom map for database schemas descriptions
|
|
||||||
*/
|
|
||||||
typedef QHash<QString, QHash<QString, QueuedDBField>> QueuedDBSchema;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup QueuedDB
|
* @defgroup QueuedDB
|
||||||
* @brief Queued database related constants
|
* @brief Queued database related constants
|
||||||
@ -56,9 +35,53 @@ typedef QHash<QString, QHash<QString, QueuedDBField>> QueuedDBSchema;
|
|||||||
namespace QueuedDB
|
namespace QueuedDB
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
*@ingroup QueuedDB
|
||||||
|
* @struct QueuedDBField
|
||||||
|
* @brief describes database column
|
||||||
|
* @var name
|
||||||
|
* column name
|
||||||
|
* @var sqlDescription
|
||||||
|
* description to create column
|
||||||
|
* @var type
|
||||||
|
* Qt type of column for cast
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
QString name;
|
||||||
|
QString sqlDescription;
|
||||||
|
QVariant::Type type;
|
||||||
|
} QueuedDBField;
|
||||||
|
/**
|
||||||
|
* @ingroup QueuedDB
|
||||||
|
* @typedef QueuedDBSchema
|
||||||
|
* custom map for database schemas descriptions
|
||||||
|
*/
|
||||||
|
typedef QHash<QString, QHash<QString, QueuedDBField>> QueuedDBSchema;
|
||||||
|
/**
|
||||||
|
* @ingroup QueuedDB
|
||||||
* @brief database schema
|
* @brief database schema
|
||||||
*/
|
*/
|
||||||
const QueuedDBSchema DBSchema = {
|
const QueuedDBSchema DBSchema = {
|
||||||
|
{"settings",
|
||||||
|
{{"_id",
|
||||||
|
{"_id", "INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE", QVariant::LongLong}},
|
||||||
|
{"key", {"key", "TEXT NOT NULL DEFAULT '0'", QVariant::String}},
|
||||||
|
{"value", {"value", "TEXT", QVariant::String}}}},
|
||||||
|
{"tasks",
|
||||||
|
{{"_id",
|
||||||
|
{"_id", "INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE", QVariant::LongLong}},
|
||||||
|
{"userId", {"userId", "INT NOT NULL DEFAULT 0", QVariant::LongLong}},
|
||||||
|
{"command", {"command", "TEXT", QVariant::String}},
|
||||||
|
{"arguments", {"arguments", "TEXT", QVariant::String}},
|
||||||
|
{"workDirectory", {"workDirectory", "TEXT", QVariant::String}},
|
||||||
|
{"nice", {"nice", "INT", QVariant::UInt}},
|
||||||
|
{"startTime", {"startTime", "INT", QVariant::LongLong}},
|
||||||
|
{"endTime", {"endTime", "INT", QVariant::LongLong}}}},
|
||||||
|
{"tokens",
|
||||||
|
{{"_id",
|
||||||
|
{"_id", "INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE", QVariant::LongLong}},
|
||||||
|
{"token", {"token", "TEXT NOT NULL DEFAULT '0'", QVariant::String}},
|
||||||
|
{"validUntil",
|
||||||
|
{"validUntil", "TEXT NOT NULL DEFAULT '0'", QVariant::String}}}},
|
||||||
{"users",
|
{"users",
|
||||||
{{"_id",
|
{{"_id",
|
||||||
{"_id", "INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE", QVariant::LongLong}},
|
{"_id", "INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE", QVariant::LongLong}},
|
||||||
@ -70,17 +93,7 @@ const QueuedDBSchema DBSchema = {
|
|||||||
{"memory", {"memory", "INT", QVariant::LongLong}},
|
{"memory", {"memory", "INT", QVariant::LongLong}},
|
||||||
{"gpumemory", {"gpumemory", "INT", QVariant::LongLong}},
|
{"gpumemory", {"gpumemory", "INT", QVariant::LongLong}},
|
||||||
{"storage", {"storage", "INT", QVariant::LongLong}},
|
{"storage", {"storage", "INT", QVariant::LongLong}},
|
||||||
{"permissions", {"permissions", "INT", QVariant::UInt}}}},
|
{"permissions", {"permissions", "INT", QVariant::UInt}}}}};
|
||||||
{"tasks",
|
|
||||||
{{"_id",
|
|
||||||
{"_id", "INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE", QVariant::LongLong}},
|
|
||||||
{"userId", {"userId", "INT NOT NULL DEFAULT 0", QVariant::LongLong}},
|
|
||||||
{"command", {"command", "TEXT", QVariant::String}},
|
|
||||||
{"arguments", {"arguments", "TEXT", QVariant::String}},
|
|
||||||
{"workDirectory", {"workDirectory", "TEXT", QVariant::String}},
|
|
||||||
{"nice", {"nice", "INT", QVariant::UInt}},
|
|
||||||
{"startTime", {"startTime", "INT", QVariant::LongLong}},
|
|
||||||
{"endTime", {"endTime", "INT", QVariant::LongLong}}}}};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* QUEUEDDATABASESCHEMA_H */
|
#endif /* QUEUEDDATABASESCHEMA_H */
|
||||||
|
@ -55,6 +55,7 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_SERV)
|
|||||||
namespace QueuedDebug
|
namespace QueuedDebug
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* @ingroup QueuedDebug
|
||||||
* @brief default log format
|
* @brief default log format
|
||||||
*/
|
*/
|
||||||
const char LOG_FORMAT[] = "[%{time "
|
const char LOG_FORMAT[] = "[%{time "
|
||||||
@ -64,6 +65,7 @@ const char LOG_FORMAT[] = "[%{time "
|
|||||||
"%{message}";
|
"%{message}";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @ingroup QueuedDebug
|
||||||
* @brief additional method to get build details declared in version.h
|
* @brief additional method to get build details declared in version.h
|
||||||
*/
|
*/
|
||||||
QStringList getBuildData();
|
QStringList getBuildData();
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
namespace QueuedEnums
|
namespace QueuedEnums
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* @ingroup QueuedEnums
|
||||||
* @enum LimitType
|
* @enum LimitType
|
||||||
* @brief available limit types
|
* @brief available limit types
|
||||||
* @var LimitType::CPUThreads
|
* @var LimitType::CPUThreads
|
||||||
@ -54,9 +55,8 @@ enum LimitType {
|
|||||||
};
|
};
|
||||||
Q_DECLARE_FLAGS(LimitTypes, LimitType)
|
Q_DECLARE_FLAGS(LimitTypes, LimitType)
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(LimitTypes)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(LimitTypes)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @ingroup QueuedEnums
|
||||||
* @enum Permissions
|
* @enum Permissions
|
||||||
* @brief available user permissions
|
* @brief available user permissions
|
||||||
* @var Permissions::Admin
|
* @var Permissions::Admin
|
||||||
|
@ -31,6 +31,16 @@
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @brief implementation over QProcess to run processes
|
||||||
|
*/
|
||||||
|
class QueuedProcess : public QProcess
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(long long index READ index)
|
||||||
|
Q_PROPERTY(QString name READ name)
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
* @struct QueuedProcessDefinition
|
* @struct QueuedProcessDefinition
|
||||||
* @brief structure to define process
|
* @brief structure to define process
|
||||||
* @var cmd
|
* @var cmd
|
||||||
@ -44,25 +54,14 @@
|
|||||||
* @var gid
|
* @var gid
|
||||||
* GID of process
|
* GID of process
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
QString cmd;
|
QString cmd;
|
||||||
QStringList args;
|
QStringList args;
|
||||||
QString workingDirectory;
|
QString workingDirectory;
|
||||||
unsigned int uid;
|
unsigned int uid;
|
||||||
unsigned int gid;
|
unsigned int gid;
|
||||||
} QueuedProcessDefinitions;
|
} QueuedProcessDefinitions;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief implementation over QProcess to run processes
|
|
||||||
*/
|
|
||||||
class QueuedProcess : public QProcess
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
Q_PROPERTY(long long index READ index)
|
|
||||||
Q_PROPERTY(QString name READ name)
|
|
||||||
|
|
||||||
public:
|
|
||||||
/**
|
/**
|
||||||
* @brief QueuedProcess class constructor
|
* @brief QueuedProcess class constructor
|
||||||
* @param parent pointer to parent item
|
* @param parent pointer to parent item
|
||||||
@ -129,14 +128,15 @@ private:
|
|||||||
/**
|
/**
|
||||||
* @brief limits array
|
* @brief limits array
|
||||||
*/
|
*/
|
||||||
QMap<QueuedEnums::LimitType, long long> m_limits;
|
QHash<QueuedEnums::LimitType, long long> m_limits;
|
||||||
/**
|
/**
|
||||||
* @brief convert QString memory value to integer
|
* @brief convert QString memory value to integer
|
||||||
* @param _value value to convert
|
* @param _value value to convert
|
||||||
* @param _status convertion status
|
* @param _status conversion status
|
||||||
* @return converted integer
|
* @return converted integer
|
||||||
*/
|
*/
|
||||||
long long convertMemory(QString _value, bool &_status) const;
|
long long convertMemory(QString _value, bool *_status) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* QUEUEDPROCESS_H */
|
#endif /* QUEUEDPROCESS_H */
|
||||||
|
@ -31,17 +31,6 @@
|
|||||||
#include "QueuedProcess.h"
|
#include "QueuedProcess.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef QueuedProcessMap
|
|
||||||
* map of indices to QueuedProcess pointers
|
|
||||||
*/
|
|
||||||
typedef QHash<long long, QueuedProcess *> QueuedProcessMap;
|
|
||||||
/**
|
|
||||||
* @typedef QueuedProcessConnectionMap
|
|
||||||
* map of indices to related QMetaObject::Connection
|
|
||||||
*/
|
|
||||||
typedef QHash<long long, QMetaObject::Connection> QueuedProcessConnectionMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief implementation over QProcess to run processes
|
* @brief implementation over QProcess to run processes
|
||||||
*/
|
*/
|
||||||
@ -52,6 +41,18 @@ class QueuedProcessManager : public QObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
* @typedef QueuedProcessMap
|
||||||
|
* map of indices to QueuedProcess pointers
|
||||||
|
*/
|
||||||
|
typedef QHash<long long, QueuedProcess *> QueuedProcessMap;
|
||||||
|
/**
|
||||||
|
* @typedef QueuedProcessConnectionMap
|
||||||
|
* map of indices to related QMetaObject::Connection
|
||||||
|
*/
|
||||||
|
typedef QHash<long long, QMetaObject::Connection>
|
||||||
|
QueuedProcessConnectionMap;
|
||||||
|
|
||||||
|
/**
|
||||||
* @enum OnExitAction
|
* @enum OnExitAction
|
||||||
* @brief action with child process on destruction
|
* @brief action with child process on destruction
|
||||||
* @var OnExitAction::Terminate
|
* @var OnExitAction::Terminate
|
||||||
@ -77,8 +78,9 @@ public:
|
|||||||
* @param _definitions process definitions
|
* @param _definitions process definitions
|
||||||
* @return pointer to created task
|
* @return pointer to created task
|
||||||
*/
|
*/
|
||||||
QueuedProcess *add(const long long _index,
|
QueuedProcess *
|
||||||
const QueuedProcessDefinitions _definitions);
|
add(const long long _index,
|
||||||
|
const QueuedProcess::QueuedProcessDefinitions _definitions);
|
||||||
/**
|
/**
|
||||||
* @brief default action on exit
|
* @brief default action on exit
|
||||||
* @return default action from possible ones
|
* @return default action from possible ones
|
||||||
@ -146,4 +148,5 @@ private:
|
|||||||
QueuedProcessMap m_processes;
|
QueuedProcessMap m_processes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* QUEUEDPROCESS_H */
|
#endif /* QUEUEDPROCESS_H */
|
||||||
|
96
sources/queued/include/queued/QueuedSettings.h
Normal file
96
sources/queued/include/queued/QueuedSettings.h
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Evgeniy Alekseev
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
*
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file QueuedSettings.h
|
||||||
|
* Header of Queued library
|
||||||
|
* @author Evgeniy Alekseev
|
||||||
|
* @copyright MIT
|
||||||
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef QUEUEDSETTINGS_H
|
||||||
|
#define QUEUEDSETTINGS_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#include "QueuedConfiguration.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief implementation over QSettings
|
||||||
|
*/
|
||||||
|
class QueuedSettings : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString path READ path)
|
||||||
|
Q_PROPERTY(QueuedCfg::QueuedAdminSetup admin READ admin)
|
||||||
|
Q_PROPERTY(QueuedCfg::QueuedDBSetup db READ db)
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief QueuedSettings class constructor
|
||||||
|
* @param parent pointer to parent item
|
||||||
|
* @param path path to configuration file
|
||||||
|
*/
|
||||||
|
explicit QueuedSettings(QObject *parent, const QString path);
|
||||||
|
/**
|
||||||
|
* @brief QueuedSettings class destructor
|
||||||
|
*/
|
||||||
|
virtual ~QueuedSettings();
|
||||||
|
/**
|
||||||
|
* @brief administrator settings
|
||||||
|
* @return QueuedAdminSetup structure
|
||||||
|
*/
|
||||||
|
QueuedCfg::QueuedAdminSetup admin() const;
|
||||||
|
/**
|
||||||
|
* @brief database settings
|
||||||
|
* @return QueuedDBSetup structure
|
||||||
|
*/
|
||||||
|
QueuedCfg::QueuedDBSetup db() const;
|
||||||
|
/**
|
||||||
|
* @brief default path to configuration
|
||||||
|
* @return default path to configuration file
|
||||||
|
*/
|
||||||
|
static QString defaultPath();
|
||||||
|
/**
|
||||||
|
* @brief path to database
|
||||||
|
* @return path to used database
|
||||||
|
*/
|
||||||
|
QString path() const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
/**
|
||||||
|
* @brief read configuration from file
|
||||||
|
*/
|
||||||
|
void readConfiguration();
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* @brief admin configuration
|
||||||
|
*/
|
||||||
|
QueuedCfg::QueuedAdminSetup m_cfgAdmin;
|
||||||
|
/**
|
||||||
|
* @brief database configuration
|
||||||
|
*/
|
||||||
|
QueuedCfg::QueuedDBSetup m_cfgDB;
|
||||||
|
/**
|
||||||
|
* @brief path to configuration
|
||||||
|
*/
|
||||||
|
QString m_path;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* QUEUEDSETTINGS_H */
|
94
sources/queued/include/queued/QueuedTokenManager.h
Normal file
94
sources/queued/include/queued/QueuedTokenManager.h
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Evgeniy Alekseev
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
*
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file QueuedTokenManager.h
|
||||||
|
* Header of Queued library
|
||||||
|
* @author Evgeniy Alekseev
|
||||||
|
* @copyright MIT
|
||||||
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef QUEUEDTOKENMANAGER_H
|
||||||
|
#define QUEUEDTOKENMANAGER_H
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief token management system
|
||||||
|
*/
|
||||||
|
class QueuedTokenManager : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief QueuedTokenManager class constructor
|
||||||
|
* @param parent pointer to parent item
|
||||||
|
*/
|
||||||
|
explicit QueuedTokenManager(QObject *parent);
|
||||||
|
/**
|
||||||
|
* @brief QueuedTokenManager class destructor
|
||||||
|
*/
|
||||||
|
virtual ~QueuedTokenManager();
|
||||||
|
/**
|
||||||
|
* @brief check if token is valid
|
||||||
|
* @param _token token ID
|
||||||
|
* @return true if token is valid otherwise return false
|
||||||
|
*/
|
||||||
|
bool isTokenValid(const QString &_token);
|
||||||
|
/**
|
||||||
|
* @brief register new token
|
||||||
|
* @param _validUntil token valid until
|
||||||
|
* @return new generated token
|
||||||
|
*/
|
||||||
|
QString registerToken(const QDateTime _validUntil);
|
||||||
|
/**
|
||||||
|
* @brief upload tokens from database
|
||||||
|
* @param _value tokens from database
|
||||||
|
*/
|
||||||
|
void setValues(const QList<QVariantHash> &_values);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
/**
|
||||||
|
* @brief method which will be called on token expiring
|
||||||
|
* @param _token expired token ID
|
||||||
|
*/
|
||||||
|
void expireToken(const QString &_token);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
/**
|
||||||
|
* @brief signal which will be emitted on token expiration
|
||||||
|
* @param _token token ID
|
||||||
|
*/
|
||||||
|
void tokenExpired(const QString &_token);
|
||||||
|
/**
|
||||||
|
* @brief signal which will be emitted on newly created token
|
||||||
|
* @param _token token ID
|
||||||
|
* @param _validUntil token valid until
|
||||||
|
*/
|
||||||
|
void tokenRegistered(const QString &_token, const QDateTime &_validUntil);
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* @brief token storage
|
||||||
|
*/
|
||||||
|
QHash<QString, QDateTime> m_tokens;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* QUEUEDTOKENMANAGER_H */
|
@ -30,41 +30,6 @@
|
|||||||
#include "QueuedEnums.h"
|
#include "QueuedEnums.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @struct QueuedUserDefinition
|
|
||||||
* @brief structure to define user
|
|
||||||
* @var name
|
|
||||||
* user name
|
|
||||||
* @var email
|
|
||||||
* user email
|
|
||||||
* @var passwordSHA512
|
|
||||||
* password hash, may be empty
|
|
||||||
* @var permissions
|
|
||||||
* user permissions
|
|
||||||
* @var cpuLimit
|
|
||||||
* user limit by CPU
|
|
||||||
* @var gpuLimit
|
|
||||||
* user limit by GPU
|
|
||||||
* @var memoryLimit
|
|
||||||
* user limit by memory
|
|
||||||
* @var gpumemoryLimit
|
|
||||||
* user limit by GPU memory
|
|
||||||
* @var storageLimit
|
|
||||||
* user limit by storage
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
QString name;
|
|
||||||
QString email;
|
|
||||||
QString passwordSHA512;
|
|
||||||
unsigned int permissions;
|
|
||||||
long long cpuLimit;
|
|
||||||
long long gpuLimit;
|
|
||||||
long long memoryLimit;
|
|
||||||
long long gpumemoryLimit;
|
|
||||||
long long storageLimit;
|
|
||||||
} QueuedUserDefinitions;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief representation of user in queued
|
* @brief representation of user in queued
|
||||||
*/
|
*/
|
||||||
@ -92,6 +57,40 @@ class QueuedUser : public QObject
|
|||||||
NOTIFY userUpdated)
|
NOTIFY userUpdated)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @struct QueuedUserDefinition
|
||||||
|
* @brief structure to define user
|
||||||
|
* @var name
|
||||||
|
* user name
|
||||||
|
* @var email
|
||||||
|
* user email
|
||||||
|
* @var passwordSHA512
|
||||||
|
* password hash, may be empty
|
||||||
|
* @var permissions
|
||||||
|
* user permissions
|
||||||
|
* @var cpuLimit
|
||||||
|
* user limit by CPU
|
||||||
|
* @var gpuLimit
|
||||||
|
* user limit by GPU
|
||||||
|
* @var memoryLimit
|
||||||
|
* user limit by memory
|
||||||
|
* @var gpumemoryLimit
|
||||||
|
* user limit by GPU memory
|
||||||
|
* @var storageLimit
|
||||||
|
* user limit by storage
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
QString name;
|
||||||
|
QString email;
|
||||||
|
QString passwordSHA512;
|
||||||
|
unsigned int permissions;
|
||||||
|
long long cpuLimit;
|
||||||
|
long long gpuLimit;
|
||||||
|
long long memoryLimit;
|
||||||
|
long long gpumemoryLimit;
|
||||||
|
long long storageLimit;
|
||||||
|
} QueuedUserDefinitions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief QueuedUser class constructor
|
* @brief QueuedUser class constructor
|
||||||
* @param parent pointer to parent item
|
* @param parent pointer to parent item
|
||||||
|
55
sources/queued/src/QueuedAdvancedSettings.cpp
Normal file
55
sources/queued/src/QueuedAdvancedSettings.cpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Evgeniy Alekseev
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
*
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file QueuedAdvancedSettings.cpp
|
||||||
|
* Source code of queued library
|
||||||
|
* @author Evgeniy Alekseev
|
||||||
|
* @copyright GPLv3
|
||||||
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "queued/Queued.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class QueuedAdvancedSettings
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @fn QueuedAdvancedSettings
|
||||||
|
*/
|
||||||
|
QueuedAdvancedSettings::QueuedAdvancedSettings(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn ~QueuedAdvancedSettings
|
||||||
|
*/
|
||||||
|
QueuedAdvancedSettings::~QueuedAdvancedSettings()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn setValues
|
||||||
|
*/
|
||||||
|
void QueuedAdvancedSettings::setValues(const QList<QVariantHash> &_values)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Set values from" << _values;
|
||||||
|
}
|
@ -58,7 +58,7 @@ QueuedDatabase::~QueuedDatabase()
|
|||||||
/**
|
/**
|
||||||
* @fn add
|
* @fn add
|
||||||
*/
|
*/
|
||||||
bool QueuedDatabase::add(const QString &_table, const QVariantHash &_value)
|
long long QueuedDatabase::add(const QString &_table, const QVariantHash &_value)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Add record" << _value << "to table" << _table;
|
qCDebug(LOG_LIB) << "Add record" << _value << "to table" << _table;
|
||||||
|
|
||||||
@ -73,10 +73,10 @@ bool QueuedDatabase::add(const QString &_table, const QVariantHash &_value)
|
|||||||
if (error.isValid()) {
|
if (error.isValid()) {
|
||||||
qCCritical(LOG_LIB) << "Could not add record" << _value << "to table"
|
qCCritical(LOG_LIB) << "Could not add record" << _value << "to table"
|
||||||
<< _table << "message" << error.text();
|
<< _table << "message" << error.text();
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return lastInsertionId(_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -269,7 +269,7 @@ void QueuedDatabase::createSchema(const QString &_table)
|
|||||||
for (auto &column : schemaColumns) {
|
for (auto &column : schemaColumns) {
|
||||||
if (columns.contains(column))
|
if (columns.contains(column))
|
||||||
continue;
|
continue;
|
||||||
QueuedDBField field = QueuedDB::DBSchema[_table][column];
|
QueuedDB::QueuedDBField field = QueuedDB::DBSchema[_table][column];
|
||||||
QSqlQuery query
|
QSqlQuery query
|
||||||
= m_database.exec(QString("ALTER TABLE '%1' ADD `%2` %3")
|
= m_database.exec(QString("ALTER TABLE '%1' ADD `%2` %3")
|
||||||
.arg(_table)
|
.arg(_table)
|
||||||
@ -319,6 +319,29 @@ QueuedDatabase::getColumnsInRecord(const QStringList &_columns,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn lastInsertionId
|
||||||
|
*/
|
||||||
|
long long QueuedDatabase::lastInsertionId(const QString &_table) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Get last row ID from" << _table;
|
||||||
|
|
||||||
|
QSqlQuery query
|
||||||
|
= m_database.exec(QString("SELECT max(_id) FROM '%1'").arg(_table));
|
||||||
|
QSqlError error = query.lastError();
|
||||||
|
if (error.isValid()) {
|
||||||
|
qCCritical(LOG_LIB) << "Could not get last insertion ID";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
long long id;
|
||||||
|
while (query.next())
|
||||||
|
id = query.value(0).toLongLong();
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn getQueryPayload
|
* @fn getQueryPayload
|
||||||
*/
|
*/
|
||||||
|
@ -99,7 +99,7 @@ void QueuedProcess::setLimit(const QueuedEnums::LimitType _limitType,
|
|||||||
|
|
||||||
bool status = false;
|
bool status = false;
|
||||||
long long intValue = _value.type() == QVariant::String
|
long long intValue = _value.type() == QVariant::String
|
||||||
? convertMemory(_value.toString(), status)
|
? convertMemory(_value.toString(), &status)
|
||||||
: _value.toLongLong(&status);
|
: _value.toLongLong(&status);
|
||||||
|
|
||||||
if (!status)
|
if (!status)
|
||||||
@ -141,21 +141,21 @@ void QueuedProcess::run()
|
|||||||
/**
|
/**
|
||||||
* @fn convertMemory
|
* @fn convertMemory
|
||||||
*/
|
*/
|
||||||
long long QueuedProcess::convertMemory(QString _value, bool &_status) const
|
long long QueuedProcess::convertMemory(QString _value, bool *_status) const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Convert memory value" << _value;
|
qCDebug(LOG_LIB) << "Convert memory value" << _value;
|
||||||
|
|
||||||
long long intValue;
|
long long intValue;
|
||||||
if (_value.endsWith(QString("K")))
|
if (_value.endsWith(QString("K")))
|
||||||
intValue = _value.remove(QString("K")).toLongLong(&_status) * 1024;
|
intValue = _value.remove(QString("K")).toLongLong(_status) * 1024;
|
||||||
else if (_value.endsWith(QString("M")))
|
else if (_value.endsWith(QString("M")))
|
||||||
intValue
|
intValue
|
||||||
= _value.remove(QString("M")).toLongLong(&_status) * 1024 * 1024;
|
= _value.remove(QString("M")).toLongLong(_status) * 1024 * 1024;
|
||||||
else if (_value.endsWith(QString("G")))
|
else if (_value.endsWith(QString("G")))
|
||||||
intValue = _value.remove(QString("G")).toLongLong(&_status) * 1024
|
intValue = _value.remove(QString("G")).toLongLong(_status) * 1024 * 1024
|
||||||
* 1024 * 1024;
|
* 1024;
|
||||||
else
|
else
|
||||||
intValue = _value.toInt(&_status);
|
intValue = _value.toInt(_status);
|
||||||
|
|
||||||
qCInfo(LOG_LIB) << "Converted value" << intValue;
|
qCInfo(LOG_LIB) << "Converted value" << intValue;
|
||||||
return intValue;
|
return intValue;
|
||||||
|
@ -52,9 +52,9 @@ QueuedProcessManager::~QueuedProcessManager()
|
|||||||
/**
|
/**
|
||||||
* @fn add
|
* @fn add
|
||||||
*/
|
*/
|
||||||
QueuedProcess *
|
QueuedProcess *QueuedProcessManager::add(
|
||||||
QueuedProcessManager::add(const long long _index,
|
const long long _index,
|
||||||
const QueuedProcessDefinitions _definitions)
|
const QueuedProcess::QueuedProcessDefinitions _definitions)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Add new process" << _definitions.cmd << "with index"
|
qCDebug(LOG_LIB) << "Add new process" << _definitions.cmd << "with index"
|
||||||
<< _index;
|
<< _index;
|
||||||
@ -99,7 +99,7 @@ QueuedProcess *QueuedProcessManager::process(const long long _index)
|
|||||||
/**
|
/**
|
||||||
* @fn processes
|
* @fn processes
|
||||||
*/
|
*/
|
||||||
QueuedProcessMap QueuedProcessManager::processes()
|
QueuedProcessManager::QueuedProcessMap QueuedProcessManager::processes()
|
||||||
{
|
{
|
||||||
return m_processes;
|
return m_processes;
|
||||||
}
|
}
|
||||||
|
124
sources/queued/src/QueuedSettings.cpp
Normal file
124
sources/queued/src/QueuedSettings.cpp
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Evgeniy Alekseev
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
*
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file QueuedSettings.cpp
|
||||||
|
* Source code of queued library
|
||||||
|
* @author Evgeniy Alekseev
|
||||||
|
* @copyright GPLv3
|
||||||
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "queued/Queued.h"
|
||||||
|
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class QueuedSettings
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @fn QueuedSettings
|
||||||
|
*/
|
||||||
|
QueuedSettings::QueuedSettings(QObject *parent, const QString path)
|
||||||
|
: QObject(parent)
|
||||||
|
, m_path(path)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
readConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn ~QueuedSettings
|
||||||
|
*/
|
||||||
|
QueuedSettings::~QueuedSettings()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn admin
|
||||||
|
*/
|
||||||
|
QueuedCfg::QueuedAdminSetup QueuedSettings::admin() const
|
||||||
|
{
|
||||||
|
return m_cfgAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn db
|
||||||
|
*/
|
||||||
|
QueuedCfg::QueuedDBSetup QueuedSettings::db() const
|
||||||
|
{
|
||||||
|
return m_cfgDB;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn defaultPath
|
||||||
|
*/
|
||||||
|
QString QueuedSettings::defaultPath()
|
||||||
|
{
|
||||||
|
QString fileName = QStandardPaths::locate(QStandardPaths::ConfigLocation,
|
||||||
|
QString("queued.ini"));
|
||||||
|
qCInfo(LOG_LIB) << "Found configuration file" << fileName;
|
||||||
|
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn path
|
||||||
|
*/
|
||||||
|
QString QueuedSettings::path() const
|
||||||
|
{
|
||||||
|
return m_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn readConfiguration
|
||||||
|
*/
|
||||||
|
void QueuedSettings::readConfiguration()
|
||||||
|
{
|
||||||
|
QSettings settings(m_path, QSettings::IniFormat);
|
||||||
|
qCInfo(LOG_LIB) << "Read configuration from" << settings.fileName();
|
||||||
|
|
||||||
|
// administrator related settings
|
||||||
|
settings.beginGroup(QString("Administrator"));
|
||||||
|
m_cfgAdmin.name
|
||||||
|
= settings.value(QString("Username"), QString("root")).toString();
|
||||||
|
m_cfgAdmin.password = settings.value(QString("Password")).toString();
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
// database related settings
|
||||||
|
settings.beginGroup(QString("Database"));
|
||||||
|
m_cfgDB.driver
|
||||||
|
= settings.value(QString("Driver"), QString("QSQLITE")).toString();
|
||||||
|
m_cfgDB.hostname = settings.value(QString("Hostname")).toString();
|
||||||
|
m_cfgDB.password = settings.value(QString("Password")).toString();
|
||||||
|
// get standard path for temporary files
|
||||||
|
QString defaultDB = QString("%1/queued.db")
|
||||||
|
.arg(QStandardPaths::writableLocation(
|
||||||
|
QStandardPaths::TempLocation));
|
||||||
|
m_cfgDB.path = settings.value(QString("Path"), defaultDB).toString();
|
||||||
|
m_cfgDB.port = settings.value(QString("Port")).toInt();
|
||||||
|
m_cfgDB.username = settings.value(QString("Username")).toString();
|
||||||
|
settings.endGroup();
|
||||||
|
}
|
118
sources/queued/src/QueuedTokenManager.cpp
Normal file
118
sources/queued/src/QueuedTokenManager.cpp
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Evgeniy Alekseev
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
*
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file QueuedTokenManager.cpp
|
||||||
|
* Source code of queued library
|
||||||
|
* @author Evgeniy Alekseev
|
||||||
|
* @copyright GPLv3
|
||||||
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "queued/Queued.h"
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class QueuedTokenManager
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @fn QueuedTokenManager
|
||||||
|
*/
|
||||||
|
QueuedTokenManager::QueuedTokenManager(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn ~QueuedTokenManager
|
||||||
|
*/
|
||||||
|
QueuedTokenManager::~QueuedTokenManager()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn isTokenValid
|
||||||
|
*/
|
||||||
|
bool QueuedTokenManager::isTokenValid(const QString &_token)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Check token on validity" << _token;
|
||||||
|
|
||||||
|
return m_tokens.contains(_token);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn registerToken
|
||||||
|
*/
|
||||||
|
QString QueuedTokenManager::registerToken(const QDateTime _validUntil)
|
||||||
|
{
|
||||||
|
// generate from uuid
|
||||||
|
QString token
|
||||||
|
= QUuid::createUuid().toString().remove(QChar('{')).remove(QChar('}'));
|
||||||
|
qCInfo(LOG_LIB) << "Registered token" << token << "valid until"
|
||||||
|
<< _validUntil;
|
||||||
|
|
||||||
|
// append to internal storage
|
||||||
|
m_tokens[token] = _validUntil;
|
||||||
|
emit(tokenRegistered(token, _validUntil));
|
||||||
|
|
||||||
|
// and return requester
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn setValues
|
||||||
|
*/
|
||||||
|
void QueuedTokenManager::setValues(const QList<QVariantHash> &_values)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Set values from" << _values;
|
||||||
|
|
||||||
|
QDateTime now = QDateTime::currentDateTimeUtc();
|
||||||
|
m_tokens.clear();
|
||||||
|
for (auto &token : _values) {
|
||||||
|
QDateTime validUntil = QDateTime::fromString(
|
||||||
|
token[QString("validUntil")].toString(), Qt::ISODate);
|
||||||
|
if (validUntil <= now)
|
||||||
|
continue;
|
||||||
|
QString tokenId = token[QString("token")].toString();
|
||||||
|
m_tokens[tokenId] = validUntil;
|
||||||
|
QTimer::singleShot(validUntil.toMSecsSinceEpoch()
|
||||||
|
- now.toMSecsSinceEpoch(),
|
||||||
|
Qt::VeryCoarseTimer,
|
||||||
|
[this, tokenId]() { return expireToken(tokenId); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn expireToken
|
||||||
|
*/
|
||||||
|
void QueuedTokenManager::expireToken(const QString &_token)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Expire token" << _token;
|
||||||
|
|
||||||
|
if (!m_tokens.contains(_token))
|
||||||
|
return;
|
||||||
|
m_tokens.remove(_token);
|
||||||
|
emit(tokenExpired(_token));
|
||||||
|
}
|
@ -32,7 +32,8 @@
|
|||||||
/**
|
/**
|
||||||
* @fn QueuedUser
|
* @fn QueuedUser
|
||||||
*/
|
*/
|
||||||
QueuedUser::QueuedUser(QObject *parent, const QueuedUserDefinitions &definitions,
|
QueuedUser::QueuedUser(QObject *parent,
|
||||||
|
const QueuedUserDefinitions &definitions,
|
||||||
const long long index)
|
const long long index)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_definitions(definitions)
|
, m_definitions(definitions)
|
||||||
|
@ -19,6 +19,13 @@ const char SPECIAL_THANKS[] = "";
|
|||||||
#cmakedefine BUILD_LOAD
|
#cmakedefine BUILD_LOAD
|
||||||
#cmakedefine BUILD_TESTING
|
#cmakedefine BUILD_TESTING
|
||||||
|
|
||||||
|
// paths
|
||||||
|
const char BIN_INSTALL_DIR[] = "@BIN_INSTALL_DIR@";
|
||||||
|
const char DATA_INSTALL_DIR[] = "@DATA_INSTALL_DIR@";
|
||||||
|
const char INCLUDE_INSTALL_DIR[] = "@INCLUDE_INSTALL_DIR@";
|
||||||
|
const char LIB_INSTALL_DIR[] = "@LIB_INSTALL_DIR@";
|
||||||
|
const char ROOT_INSTALL_DIR[] = "@CMAKE_INSTALL_PREFIX@";
|
||||||
|
|
||||||
// links
|
// links
|
||||||
const char HOMEPAGE[] = "https://arcanis.me/projects/queued";
|
const char HOMEPAGE[] = "https://arcanis.me/projects/queued";
|
||||||
const char REPOSITORY[] = "https://github.com/arcan1s/queued";
|
const char REPOSITORY[] = "https://github.com/arcan1s/queued";
|
||||||
|
Loading…
Reference in New Issue
Block a user