mirror of
https://github.com/arcan1s/queued.git
synced 2025-07-14 14:25:48 +00:00
use 100 symbols (2)
This commit is contained in:
@ -46,33 +46,26 @@ QueuedServer::~QueuedServer()
|
||||
void QueuedServer::init()
|
||||
{
|
||||
while (QueuedCoreAdaptor::getStatus().type() != Result::Content::Value) {
|
||||
qCWarning(LOG_SERV)
|
||||
<< "Daemon seems to be unavailable wait" << WAIT_FOR_DAEMON;
|
||||
qCWarning(LOG_SERV) << "Daemon seems to be unavailable wait" << WAIT_FOR_DAEMON;
|
||||
|
||||
QTime timer = QTime::currentTime().addMSecs(WAIT_FOR_DAEMON);
|
||||
while (QTime::currentTime() < timer)
|
||||
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
|
||||
}
|
||||
|
||||
m_server->init(QueuedCoreAdaptor::getOption(
|
||||
QueuedConfig::QueuedSettings::ServerTimeout, "")
|
||||
m_server->init(QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::ServerTimeout, "")
|
||||
.get()
|
||||
.toInt());
|
||||
QString address = QueuedCoreAdaptor::getOption(
|
||||
QueuedConfig::QueuedSettings::ServerAddress, "")
|
||||
QString address = QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::ServerAddress, "")
|
||||
.get()
|
||||
.toString();
|
||||
ushort port = QueuedCoreAdaptor::getOption(
|
||||
QueuedConfig::QueuedSettings::ServerPort, "")
|
||||
.get()
|
||||
.toUInt();
|
||||
ushort port
|
||||
= QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::ServerPort, "").get().toUInt();
|
||||
m_server->listen(QHostAddress(address), port);
|
||||
m_server->setMaxPendingConnections(
|
||||
QueuedCoreAdaptor::getOption(
|
||||
QueuedConfig::QueuedSettings::ServerMaxConnections, "")
|
||||
QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::ServerMaxConnections, "")
|
||||
.get()
|
||||
.toInt());
|
||||
|
||||
qCInfo(LOG_SERV) << "Server listen on" << m_server->serverAddress()
|
||||
<< m_server->serverPort();
|
||||
qCInfo(LOG_SERV) << "Server listen on" << m_server->serverAddress() << m_server->serverPort();
|
||||
}
|
||||
|
@ -27,14 +27,13 @@ QVariantHash QueuedTcpServerResponseHelper::getData(const Request &_request,
|
||||
const QVariantHash &_data,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Get data for request"
|
||||
<< static_cast<int>(_request.path) << _request.apiVersion
|
||||
<< _request.arg << "with data" << _data;
|
||||
qCDebug(LOG_SERV) << "Get data for request" << static_cast<int>(_request.path)
|
||||
<< _request.apiVersion << _request.arg << "with data" << _data;
|
||||
|
||||
QVariantHash output;
|
||||
if (_request.apiVersion == 1)
|
||||
output = QueuedTcpServerResponseHelperApi1::getData(
|
||||
_request.path, _request.arg, _request.type, _data, _token);
|
||||
output = QueuedTcpServerResponseHelperApi1::getData(_request.path, _request.arg,
|
||||
_request.type, _data, _token);
|
||||
|
||||
return output;
|
||||
}
|
||||
@ -64,8 +63,7 @@ QueuedTcpServerResponseHelper::parsePath(const QString &_path)
|
||||
// check if request is valid
|
||||
request.valid = (request.path != RequestPath::Unknown)
|
||||
&& (std::find(std::begin(QueuedConfig::WEBAPI_VERSIONS),
|
||||
std::end(QueuedConfig::WEBAPI_VERSIONS),
|
||||
request.apiVersion)
|
||||
std::end(QueuedConfig::WEBAPI_VERSIONS), request.apiVersion)
|
||||
!= std::end(QueuedConfig::WEBAPI_VERSIONS));
|
||||
}
|
||||
|
||||
|
@ -43,49 +43,47 @@ typedef struct {
|
||||
QString type;
|
||||
bool valid;
|
||||
} Request;
|
||||
static const QHash<int, QByteArray> HTTPCodeMap
|
||||
= {{100, "Continue"},
|
||||
{101, "Switching Protocols"},
|
||||
{200, "OK"},
|
||||
{201, "Created"},
|
||||
{202, "Accepted"},
|
||||
{203, "Non-Authoritative Information"},
|
||||
{204, "No Content"},
|
||||
{205, "Reset Content"},
|
||||
{206, "Partial Content"},
|
||||
{300, "Multiple Choices"},
|
||||
{301, "Moved Permanently"},
|
||||
{302, "Found"},
|
||||
{303, "See Other"},
|
||||
{304, "Not Modified"},
|
||||
{305, "Use Proxy"},
|
||||
{307, "Temporary Redirect"},
|
||||
{400, "Bad Request"},
|
||||
{401, "Unauthorized"},
|
||||
{402, "Payment Required"},
|
||||
{403, "Forbidden"},
|
||||
{404, "Not Found"},
|
||||
{405, "Method Not Allowed"},
|
||||
{406, "Not Acceptable"},
|
||||
{407, "Proxy Authentication Required"},
|
||||
{408, "Request Time-out"},
|
||||
{409, "Conflict"},
|
||||
{410, "Gone"},
|
||||
{411, "Length Required"},
|
||||
{412, "Precondition Failed"},
|
||||
{413, "Request Entity Too Large"},
|
||||
{414, "Request-URI Too Large"},
|
||||
{415, "Unsupported Media Type"},
|
||||
{416, "Requested range not satisfiable"},
|
||||
{417, "Expectation Failed"},
|
||||
{500, "Internal Server Error"},
|
||||
{501, "Not Implemented"},
|
||||
{502, "Bad Gateway"},
|
||||
{503, "Service Unavailable"},
|
||||
{504, "Gateway Time-out"},
|
||||
{505, "HTTP Version not supported"}};
|
||||
QVariantHash getData(const Request &_request, const QVariantHash &_data,
|
||||
const QString &_token);
|
||||
static const QHash<int, QByteArray> HTTPCodeMap = {{100, "Continue"},
|
||||
{101, "Switching Protocols"},
|
||||
{200, "OK"},
|
||||
{201, "Created"},
|
||||
{202, "Accepted"},
|
||||
{203, "Non-Authoritative Information"},
|
||||
{204, "No Content"},
|
||||
{205, "Reset Content"},
|
||||
{206, "Partial Content"},
|
||||
{300, "Multiple Choices"},
|
||||
{301, "Moved Permanently"},
|
||||
{302, "Found"},
|
||||
{303, "See Other"},
|
||||
{304, "Not Modified"},
|
||||
{305, "Use Proxy"},
|
||||
{307, "Temporary Redirect"},
|
||||
{400, "Bad Request"},
|
||||
{401, "Unauthorized"},
|
||||
{402, "Payment Required"},
|
||||
{403, "Forbidden"},
|
||||
{404, "Not Found"},
|
||||
{405, "Method Not Allowed"},
|
||||
{406, "Not Acceptable"},
|
||||
{407, "Proxy Authentication Required"},
|
||||
{408, "Request Time-out"},
|
||||
{409, "Conflict"},
|
||||
{410, "Gone"},
|
||||
{411, "Length Required"},
|
||||
{412, "Precondition Failed"},
|
||||
{413, "Request Entity Too Large"},
|
||||
{414, "Request-URI Too Large"},
|
||||
{415, "Unsupported Media Type"},
|
||||
{416, "Requested range not satisfiable"},
|
||||
{417, "Expectation Failed"},
|
||||
{500, "Internal Server Error"},
|
||||
{501, "Not Implemented"},
|
||||
{502, "Bad Gateway"},
|
||||
{503, "Service Unavailable"},
|
||||
{504, "Gateway Time-out"},
|
||||
{505, "HTTP Version not supported"}};
|
||||
QVariantHash getData(const Request &_request, const QVariantHash &_data, const QString &_token);
|
||||
Request parsePath(const QString &_path);
|
||||
RequestPath pathToEnum(const QString &_path);
|
||||
};
|
||||
|
@ -27,12 +27,11 @@
|
||||
|
||||
|
||||
QVariantHash QueuedTcpServerResponseHelperApi1::getData(
|
||||
const QueuedTcpServerResponseHelper::RequestPath _request,
|
||||
const QString &_arg, const QString &_type, const QVariantHash &_data,
|
||||
const QString &_token)
|
||||
const QueuedTcpServerResponseHelper::RequestPath _request, const QString &_arg,
|
||||
const QString &_type, const QVariantHash &_data, const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Get data for" << static_cast<int>(_request)
|
||||
<< "with arg" << _arg << "with data" << _data;
|
||||
qCDebug(LOG_SERV) << "Get data for" << static_cast<int>(_request) << "with arg" << _arg
|
||||
<< "with data" << _data;
|
||||
|
||||
QVariantHash output;
|
||||
if ((_request != QueuedTcpServerResponseHelper::RequestPath::Auth)
|
||||
@ -50,47 +49,41 @@ QVariantHash QueuedTcpServerResponseHelperApi1::getData(
|
||||
break;
|
||||
case QueuedTcpServerResponseHelper::RequestPath::Option:
|
||||
if (_type == "GET")
|
||||
output
|
||||
= QueuedTcpServerResponseHelperOption::getOption(_arg, _token);
|
||||
output = QueuedTcpServerResponseHelperOption::getOption(_arg, _token);
|
||||
else if (_type == "POST")
|
||||
output = QueuedTcpServerResponseHelperOption::setOption(_arg, _data,
|
||||
_token);
|
||||
output = QueuedTcpServerResponseHelperOption::setOption(_arg, _data, _token);
|
||||
else
|
||||
output = {{"code", 405}};
|
||||
break;
|
||||
case QueuedTcpServerResponseHelper::RequestPath::Permissions:
|
||||
if (_type == "DELETE")
|
||||
output = QueuedTcpServerResponseHelperPermissions::removePermission(
|
||||
_arg.toLongLong(), _data, _token);
|
||||
output = QueuedTcpServerResponseHelperPermissions::removePermission(_arg.toLongLong(),
|
||||
_data, _token);
|
||||
else if (_type == "POST")
|
||||
output = QueuedTcpServerResponseHelperPermissions::addPermission(
|
||||
_arg.toLongLong(), _data, _token);
|
||||
output = QueuedTcpServerResponseHelperPermissions::addPermission(_arg.toLongLong(),
|
||||
_data, _token);
|
||||
else
|
||||
output = {{"code", 405}};
|
||||
break;
|
||||
case QueuedTcpServerResponseHelper::RequestPath::Plugin:
|
||||
if (_type == "GET")
|
||||
output
|
||||
= QueuedTcpServerResponseHelperPlugins::getPlugin(_arg, _token);
|
||||
output = QueuedTcpServerResponseHelperPlugins::getPlugin(_arg, _token);
|
||||
else
|
||||
output = {{"code", 405}};
|
||||
break;
|
||||
case QueuedTcpServerResponseHelper::RequestPath::Plugins:
|
||||
if (_type == "DELETE")
|
||||
output = QueuedTcpServerResponseHelperPlugins::removePlugin(_arg,
|
||||
_token);
|
||||
output = QueuedTcpServerResponseHelperPlugins::removePlugin(_arg, _token);
|
||||
else if (_type == "GET")
|
||||
output = QueuedTcpServerResponseHelperPlugins::listPlugins();
|
||||
else if (_type == "POST")
|
||||
output
|
||||
= QueuedTcpServerResponseHelperPlugins::addPlugin(_arg, _token);
|
||||
output = QueuedTcpServerResponseHelperPlugins::addPlugin(_arg, _token);
|
||||
else
|
||||
output = {{"code", 405}};
|
||||
break;
|
||||
case QueuedTcpServerResponseHelper::RequestPath::Reports:
|
||||
if (_type == "GET")
|
||||
output
|
||||
= QueuedTcpServerResponseHelperUser::getReport(_data, _token);
|
||||
output = QueuedTcpServerResponseHelperUser::getReport(_data, _token);
|
||||
else
|
||||
output = {{"code", 405}};
|
||||
break;
|
||||
@ -102,14 +95,12 @@ QVariantHash QueuedTcpServerResponseHelperApi1::getData(
|
||||
break;
|
||||
case QueuedTcpServerResponseHelper::RequestPath::Task:
|
||||
if (_type == "GET")
|
||||
output = QueuedTcpServerResponseHelperTask::getTask(
|
||||
_arg.toLongLong(), _data, _token);
|
||||
output = QueuedTcpServerResponseHelperTask::getTask(_arg.toLongLong(), _data, _token);
|
||||
else if (_type == "POST")
|
||||
output = QueuedTcpServerResponseHelperTask::addOrEditTask(
|
||||
_arg.toLongLong(), _data, _token);
|
||||
output = QueuedTcpServerResponseHelperTask::addOrEditTask(_arg.toLongLong(), _data,
|
||||
_token);
|
||||
else if (_type == "PUT")
|
||||
output = QueuedTcpServerResponseHelperTask::startOrStopTask(
|
||||
_arg.toLongLong(), _token);
|
||||
output = QueuedTcpServerResponseHelperTask::startOrStopTask(_arg.toLongLong(), _token);
|
||||
else
|
||||
output = {{"code", 405}};
|
||||
break;
|
||||
@ -121,11 +112,9 @@ QVariantHash QueuedTcpServerResponseHelperApi1::getData(
|
||||
break;
|
||||
case QueuedTcpServerResponseHelper::RequestPath::User:
|
||||
if (_type == "GET")
|
||||
output = QueuedTcpServerResponseHelperUser::getUser(_arg, _data,
|
||||
_token);
|
||||
output = QueuedTcpServerResponseHelperUser::getUser(_arg, _data, _token);
|
||||
else if (_type == "POST")
|
||||
output = QueuedTcpServerResponseHelperUser::addOrEditUser(
|
||||
_arg, _data, _token);
|
||||
output = QueuedTcpServerResponseHelperUser::addOrEditUser(_arg, _data, _token);
|
||||
else
|
||||
output = {{"code", 405}};
|
||||
break;
|
||||
|
@ -24,9 +24,8 @@
|
||||
|
||||
namespace QueuedTcpServerResponseHelperApi1
|
||||
{
|
||||
QVariantHash getData(const QueuedTcpServerResponseHelper::RequestPath _request,
|
||||
const QString &_arg, const QString &_type,
|
||||
const QVariantHash &_data, const QString &_token);
|
||||
QVariantHash getData(const QueuedTcpServerResponseHelper::RequestPath _request, const QString &_arg,
|
||||
const QString &_type, const QVariantHash &_data, const QString &_token);
|
||||
QVariantHash getStatus();
|
||||
};
|
||||
|
||||
|
@ -25,8 +25,7 @@ QVariantHash QueuedTcpServerResponseHelperAuth::auth(const QVariantHash &_data)
|
||||
|
||||
QVariantHash output;
|
||||
if (_data.contains("user") && _data.contains("password")) {
|
||||
auto res = QueuedCoreAdaptor::auth(_data["user"].toString(),
|
||||
_data["password"].toString());
|
||||
auto res = QueuedCoreAdaptor::auth(_data["user"].toString(), _data["password"].toString());
|
||||
|
||||
res.match(
|
||||
[&output](const QString &val) {
|
||||
|
@ -19,9 +19,8 @@
|
||||
#include <queued/Queued.h>
|
||||
|
||||
|
||||
QVariantHash
|
||||
QueuedTcpServerResponseHelperOption::getOption(const QString &_option,
|
||||
const QString &_token)
|
||||
QVariantHash QueuedTcpServerResponseHelperOption::getOption(const QString &_option,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Get option" << _option;
|
||||
|
||||
@ -41,16 +40,16 @@ QueuedTcpServerResponseHelperOption::getOption(const QString &_option,
|
||||
}
|
||||
|
||||
|
||||
QVariantHash QueuedTcpServerResponseHelperOption::setOption(
|
||||
const QString &_option, const QVariantHash &_value, const QString &_token)
|
||||
QVariantHash QueuedTcpServerResponseHelperOption::setOption(const QString &_option,
|
||||
const QVariantHash &_value,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Set option" << _option << "to" << _value;
|
||||
|
||||
if (!_value.contains("value"))
|
||||
return {{"code", 400}, {"message", "No required fields found"}};
|
||||
|
||||
auto res
|
||||
= QueuedCoreAdaptor::sendOptionEdit(_option, _value["value"], _token);
|
||||
auto res = QueuedCoreAdaptor::sendOptionEdit(_option, _value["value"], _token);
|
||||
|
||||
QVariantHash output;
|
||||
res.match(
|
||||
|
@ -23,8 +23,7 @@
|
||||
namespace QueuedTcpServerResponseHelperOption
|
||||
{
|
||||
QVariantHash getOption(const QString &_option, const QString &_token);
|
||||
QVariantHash setOption(const QString &_option, const QVariantHash &_value,
|
||||
const QString &_token);
|
||||
QVariantHash setOption(const QString &_option, const QVariantHash &_value, const QString &_token);
|
||||
};
|
||||
|
||||
|
||||
|
@ -19,21 +19,20 @@
|
||||
#include <queued/Queued.h>
|
||||
|
||||
|
||||
QVariantHash QueuedTcpServerResponseHelperPermissions::addPermission(
|
||||
const long long _id, const QVariantHash &_value, const QString &_token)
|
||||
QVariantHash QueuedTcpServerResponseHelperPermissions::addPermission(const long long _id,
|
||||
const QVariantHash &_value,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Add permission for" << _id << _value;
|
||||
|
||||
if (!_value.contains("permission"))
|
||||
return {{"code", 400}, {"message", "No required fields found"}};
|
||||
|
||||
auto permission
|
||||
= QueuedEnums::stringToPermission(_value["permission"].toString());
|
||||
auto permission = QueuedEnums::stringToPermission(_value["permission"].toString());
|
||||
if (permission == QueuedEnums::Permission::Invalid)
|
||||
return {{"code", 400}, {"message", "Invalid permission"}};
|
||||
|
||||
auto res
|
||||
= QueuedCoreAdaptor::sendUserPermissionAdd(_id, permission, _token);
|
||||
auto res = QueuedCoreAdaptor::sendUserPermissionAdd(_id, permission, _token);
|
||||
|
||||
QVariantHash output;
|
||||
res.match(
|
||||
@ -48,21 +47,20 @@ QVariantHash QueuedTcpServerResponseHelperPermissions::addPermission(
|
||||
}
|
||||
|
||||
|
||||
QVariantHash QueuedTcpServerResponseHelperPermissions::removePermission(
|
||||
const long long _id, const QVariantHash &_value, const QString &_token)
|
||||
QVariantHash QueuedTcpServerResponseHelperPermissions::removePermission(const long long _id,
|
||||
const QVariantHash &_value,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Remove permission for" << _id << _value;
|
||||
|
||||
if (!_value.contains("permission"))
|
||||
return {{"code", 400}, {"message", "No required fields found"}};
|
||||
|
||||
auto permission
|
||||
= QueuedEnums::stringToPermission(_value["permission"].toString());
|
||||
auto permission = QueuedEnums::stringToPermission(_value["permission"].toString());
|
||||
if (permission == QueuedEnums::Permission::Invalid)
|
||||
return {{"code", 400}, {"message", "Invalid permission"}};
|
||||
|
||||
auto res
|
||||
= QueuedCoreAdaptor::sendUserPermissionRemove(_id, permission, _token);
|
||||
auto res = QueuedCoreAdaptor::sendUserPermissionRemove(_id, permission, _token);
|
||||
|
||||
QVariantHash output;
|
||||
res.match(
|
||||
|
@ -22,8 +22,7 @@
|
||||
|
||||
namespace QueuedTcpServerResponseHelperPermissions
|
||||
{
|
||||
QVariantHash addPermission(const long long _id, const QVariantHash &_value,
|
||||
const QString &_token);
|
||||
QVariantHash addPermission(const long long _id, const QVariantHash &_value, const QString &_token);
|
||||
QVariantHash removePermission(const long long _id, const QVariantHash &_value,
|
||||
const QString &_token);
|
||||
};
|
||||
|
@ -19,9 +19,8 @@
|
||||
#include <queued/Queued.h>
|
||||
|
||||
|
||||
QVariantHash
|
||||
QueuedTcpServerResponseHelperPlugins::addPlugin(const QString &_name,
|
||||
const QString &_token)
|
||||
QVariantHash QueuedTcpServerResponseHelperPlugins::addPlugin(const QString &_name,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Add plugin" << _name;
|
||||
|
||||
@ -40,9 +39,8 @@ QueuedTcpServerResponseHelperPlugins::addPlugin(const QString &_name,
|
||||
}
|
||||
|
||||
|
||||
QVariantHash
|
||||
QueuedTcpServerResponseHelperPlugins::getPlugin(const QString &_name,
|
||||
const QString &_token)
|
||||
QVariantHash QueuedTcpServerResponseHelperPlugins::getPlugin(const QString &_name,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Get plugin" << _name;
|
||||
|
||||
@ -65,8 +63,7 @@ QueuedTcpServerResponseHelperPlugins::getPlugin(const QString &_name,
|
||||
|
||||
QVariantHash QueuedTcpServerResponseHelperPlugins::listPlugins()
|
||||
{
|
||||
auto res = QueuedCoreAdaptor::getOption(
|
||||
QueuedConfig::QueuedSettings::Plugins, "");
|
||||
auto res = QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::Plugins, "");
|
||||
|
||||
QVariantHash output;
|
||||
res.match(
|
||||
@ -81,9 +78,8 @@ QVariantHash QueuedTcpServerResponseHelperPlugins::listPlugins()
|
||||
}
|
||||
|
||||
|
||||
QVariantHash
|
||||
QueuedTcpServerResponseHelperPlugins::removePlugin(const QString &_name,
|
||||
const QString &_token)
|
||||
QVariantHash QueuedTcpServerResponseHelperPlugins::removePlugin(const QString &_name,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Remove plugin" << _name;
|
||||
|
||||
|
@ -19,8 +19,9 @@
|
||||
#include <queued/Queued.h>
|
||||
|
||||
|
||||
QVariantHash QueuedTcpServerResponseHelperTask::addOrEditTask(
|
||||
const long long _id, const QVariantHash &_data, const QString &_token)
|
||||
QVariantHash QueuedTcpServerResponseHelperTask::addOrEditTask(const long long _id,
|
||||
const QVariantHash &_data,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Add or edit task" << _id << "with data" << _data;
|
||||
|
||||
@ -63,12 +64,10 @@ QueuedTcpServerResponseHelperTask::getDefinitions(const QVariantHash &_data)
|
||||
for (auto &arg : args)
|
||||
defs.arguments.append(arg.toString());
|
||||
defs.command = _data["command"].toString();
|
||||
defs.endTime
|
||||
= QDateTime::fromString(_data["end"].toString(), Qt::ISODateWithMs);
|
||||
defs.endTime = QDateTime::fromString(_data["end"].toString(), Qt::ISODateWithMs);
|
||||
defs.gid = _data["gid"].toUInt();
|
||||
defs.nice = _data["nice"].toUInt();
|
||||
defs.startTime
|
||||
= QDateTime::fromString(_data["start"].toString(), Qt::ISODateWithMs);
|
||||
defs.startTime = QDateTime::fromString(_data["start"].toString(), Qt::ISODateWithMs);
|
||||
defs.uid = _data["uid"].toUInt();
|
||||
defs.user = _data["user"].toLongLong();
|
||||
defs.workingDirectory = _data["workingDirectory"].toString();
|
||||
@ -85,8 +84,9 @@ QueuedTcpServerResponseHelperTask::getDefinitions(const QVariantHash &_data)
|
||||
}
|
||||
|
||||
|
||||
QVariantHash QueuedTcpServerResponseHelperTask::getTask(
|
||||
const long long _id, const QVariantHash &_data, const QString &_token)
|
||||
QVariantHash QueuedTcpServerResponseHelperTask::getTask(const long long _id,
|
||||
const QVariantHash &_data,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Get task" << _id << _data;
|
||||
|
||||
@ -95,11 +95,10 @@ QVariantHash QueuedTcpServerResponseHelperTask::getTask(
|
||||
QVariantHash output = {{"code", 200}};
|
||||
if (property.isEmpty()) {
|
||||
auto res = QueuedCoreAdaptor::getTask(_id, _token);
|
||||
res.match(
|
||||
[&output](const QVariantHash &val) { output["properties"] = val; },
|
||||
[&output](const QueuedError &err) {
|
||||
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||
});
|
||||
res.match([&output](const QVariantHash &val) { output["properties"] = val; },
|
||||
[&output](const QueuedError &err) {
|
||||
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||
});
|
||||
} else {
|
||||
auto res = QueuedCoreAdaptor::getTask(_id, property);
|
||||
res.match(
|
||||
@ -115,17 +114,14 @@ QVariantHash QueuedTcpServerResponseHelperTask::getTask(
|
||||
}
|
||||
|
||||
|
||||
QVariantHash
|
||||
QueuedTcpServerResponseHelperTask::getTasks(const QVariantHash &_data,
|
||||
const QString &_token)
|
||||
QVariantHash QueuedTcpServerResponseHelperTask::getTasks(const QVariantHash &_data,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Get tasks" << _data;
|
||||
|
||||
long long userId = _data.value("userId").toLongLong();
|
||||
QDateTime start
|
||||
= QDateTime::fromString(_data["start"].toString(), Qt::ISODateWithMs);
|
||||
QDateTime stop
|
||||
= QDateTime::fromString(_data["stop"].toString(), Qt::ISODateWithMs);
|
||||
QDateTime start = QDateTime::fromString(_data["start"].toString(), Qt::ISODateWithMs);
|
||||
QDateTime stop = QDateTime::fromString(_data["stop"].toString(), Qt::ISODateWithMs);
|
||||
|
||||
QVariantHash output;
|
||||
// some conversion magic
|
||||
@ -145,9 +141,8 @@ QueuedTcpServerResponseHelperTask::getTasks(const QVariantHash &_data,
|
||||
}
|
||||
|
||||
|
||||
QVariantHash
|
||||
QueuedTcpServerResponseHelperTask::startOrStopTask(const long long _id,
|
||||
const QString &_token)
|
||||
QVariantHash QueuedTcpServerResponseHelperTask::startOrStopTask(const long long _id,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Change task state" << _id;
|
||||
|
||||
@ -156,8 +151,7 @@ QueuedTcpServerResponseHelperTask::startOrStopTask(const long long _id,
|
||||
QVariantHash output;
|
||||
res.match(
|
||||
[&output, &_id, &_token](const QVariantHash &val) {
|
||||
if (val["startTime"].toString().isEmpty()
|
||||
|| !val["endTime"].toString().isEmpty())
|
||||
if (val["startTime"].toString().isEmpty() || !val["endTime"].toString().isEmpty())
|
||||
output = startTask(_id, _token);
|
||||
else
|
||||
output = stopTask(_id, _token);
|
||||
@ -190,8 +184,7 @@ QVariantHash QueuedTcpServerResponseHelperTask::startTask(const long long _id,
|
||||
}
|
||||
|
||||
|
||||
QVariantHash QueuedTcpServerResponseHelperTask::stopTask(const long long _id,
|
||||
const QString &_token)
|
||||
QVariantHash QueuedTcpServerResponseHelperTask::stopTask(const long long _id, const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Stop task" << _id;
|
||||
|
||||
|
@ -24,12 +24,9 @@
|
||||
|
||||
namespace QueuedTcpServerResponseHelperTask
|
||||
{
|
||||
QVariantHash addOrEditTask(const long long _id, const QVariantHash &_data,
|
||||
const QString &_token);
|
||||
QueuedProcess::QueuedProcessDefinitions
|
||||
getDefinitions(const QVariantHash &_data);
|
||||
QVariantHash getTask(const long long _id, const QVariantHash &_data,
|
||||
const QString &_token);
|
||||
QVariantHash addOrEditTask(const long long _id, const QVariantHash &_data, const QString &_token);
|
||||
QueuedProcess::QueuedProcessDefinitions getDefinitions(const QVariantHash &_data);
|
||||
QVariantHash getTask(const long long _id, const QVariantHash &_data, const QString &_token);
|
||||
QVariantHash getTasks(const QVariantHash &_data, const QString &_token);
|
||||
QVariantHash startOrStopTask(const long long _id, const QString &_token);
|
||||
QVariantHash startTask(const long long _id, const QString &_token);
|
||||
|
@ -20,8 +20,9 @@
|
||||
#include <queued/QueuedUser.h>
|
||||
|
||||
|
||||
QVariantHash QueuedTcpServerResponseHelperUser::addOrEditUser(
|
||||
const QString &_user, const QVariantHash &_data, const QString &_token)
|
||||
QVariantHash QueuedTcpServerResponseHelperUser::addOrEditUser(const QString &_user,
|
||||
const QVariantHash &_data,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Add user" << _user << "with data" << _data;
|
||||
|
||||
@ -68,10 +69,8 @@ QueuedTcpServerResponseHelperUser::getDefinitions(const QVariantHash &_data)
|
||||
|
||||
QueuedUser::QueuedUserDefinitions defs;
|
||||
defs.email = _data["email"].toString();
|
||||
auto res
|
||||
= QueuedCoreAdaptor::sendPasswordHash(_data["password"].toString());
|
||||
res.match([&defs](const QString &val) { defs.password = val; },
|
||||
[](const QueuedError &) {});
|
||||
auto res = QueuedCoreAdaptor::sendPasswordHash(_data["password"].toString());
|
||||
res.match([&defs](const QString &val) { defs.password = val; }, [](const QueuedError &) {});
|
||||
defs.permissions = _data["permissions"].toUInt();
|
||||
defs.priority = _data["priority"].toUInt();
|
||||
// limits
|
||||
@ -87,16 +86,13 @@ QueuedTcpServerResponseHelperUser::getDefinitions(const QVariantHash &_data)
|
||||
}
|
||||
|
||||
|
||||
QVariantHash
|
||||
QueuedTcpServerResponseHelperUser::getReport(const QVariantHash &_data,
|
||||
const QString &_token)
|
||||
QVariantHash QueuedTcpServerResponseHelperUser::getReport(const QVariantHash &_data,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Get report using payload" << _data;
|
||||
|
||||
QDateTime stop
|
||||
= QDateTime::fromString(_data["stop"].toString(), Qt::ISODateWithMs);
|
||||
QDateTime start
|
||||
= QDateTime::fromString(_data["start"].toString(), Qt::ISODateWithMs);
|
||||
QDateTime stop = QDateTime::fromString(_data["stop"].toString(), Qt::ISODateWithMs);
|
||||
QDateTime start = QDateTime::fromString(_data["start"].toString(), Qt::ISODateWithMs);
|
||||
|
||||
QVariantHash output = {{"code", 200}};
|
||||
// some conversion magic
|
||||
@ -116,15 +112,15 @@ QueuedTcpServerResponseHelperUser::getReport(const QVariantHash &_data,
|
||||
}
|
||||
|
||||
|
||||
QVariantHash QueuedTcpServerResponseHelperUser::getUser(
|
||||
const QString &_user, const QVariantHash &_data, const QString &_token)
|
||||
QVariantHash QueuedTcpServerResponseHelperUser::getUser(const QString &_user,
|
||||
const QVariantHash &_data,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Get user data for" << _user << _data;
|
||||
|
||||
auto userIdRes = QueuedCoreAdaptor::getUserId(_user, _token);
|
||||
long long userId = -1;
|
||||
userIdRes.match([&userId](const long long val) { userId = val; },
|
||||
[](const QueuedError &) {});
|
||||
userIdRes.match([&userId](const long long val) { userId = val; }, [](const QueuedError &) {});
|
||||
if (userId == -1)
|
||||
return {{"code", 500}};
|
||||
|
||||
@ -133,11 +129,10 @@ QVariantHash QueuedTcpServerResponseHelperUser::getUser(
|
||||
QVariantHash output = {{"code", 200}};
|
||||
if (property.isEmpty()) {
|
||||
auto res = QueuedCoreAdaptor::getUser(userId, _token);
|
||||
res.match(
|
||||
[&output](const QVariantHash &val) { output["properties"] = val; },
|
||||
[&output](const QueuedError &err) {
|
||||
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||
});
|
||||
res.match([&output](const QVariantHash &val) { output["properties"] = val; },
|
||||
[&output](const QueuedError &err) {
|
||||
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||
});
|
||||
} else {
|
||||
auto res = QueuedCoreAdaptor::getUser(userId, property);
|
||||
res.match(
|
||||
@ -153,16 +148,13 @@ QVariantHash QueuedTcpServerResponseHelperUser::getUser(
|
||||
}
|
||||
|
||||
|
||||
QVariantHash
|
||||
QueuedTcpServerResponseHelperUser::getUsers(const QVariantHash &_data,
|
||||
const QString &_token)
|
||||
QVariantHash QueuedTcpServerResponseHelperUser::getUsers(const QVariantHash &_data,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Get users" << _data;
|
||||
|
||||
QDateTime lastLogin = QDateTime::fromString(_data["lastLogged"].toString(),
|
||||
Qt::ISODateWithMs);
|
||||
auto permission
|
||||
= QueuedEnums::stringToPermission(_data["permission"].toString());
|
||||
QDateTime lastLogin = QDateTime::fromString(_data["lastLogged"].toString(), Qt::ISODateWithMs);
|
||||
auto permission = QueuedEnums::stringToPermission(_data["permission"].toString());
|
||||
|
||||
QVariantHash output = {{"code", 200}};
|
||||
// some conversion magic
|
||||
|
@ -24,12 +24,10 @@
|
||||
|
||||
namespace QueuedTcpServerResponseHelperUser
|
||||
{
|
||||
QVariantHash addOrEditUser(const QString &_user, const QVariantHash &_data,
|
||||
const QString &_token);
|
||||
QVariantHash addOrEditUser(const QString &_user, const QVariantHash &_data, const QString &_token);
|
||||
QueuedUser::QueuedUserDefinitions getDefinitions(const QVariantHash &_data);
|
||||
QVariantHash getReport(const QVariantHash &_data, const QString &_token);
|
||||
QVariantHash getUser(const QString &_user, const QVariantHash &_data,
|
||||
const QString &_token);
|
||||
QVariantHash getUser(const QString &_user, const QVariantHash &_data, const QString &_token);
|
||||
QVariantHash getUsers(const QVariantHash &_data, const QString &_token);
|
||||
};
|
||||
|
||||
|
@ -27,8 +27,8 @@
|
||||
#include "QueuedTcpServerResponseHelper.h"
|
||||
|
||||
|
||||
QueuedTcpServerThread::QueuedTcpServerThread(int socketDescriptor,
|
||||
const int timeout, QObject *parent)
|
||||
QueuedTcpServerThread::QueuedTcpServerThread(int socketDescriptor, const int timeout,
|
||||
QObject *parent)
|
||||
: QThread(parent)
|
||||
, m_socketDescriptor(socketDescriptor)
|
||||
, m_timeout(timeout)
|
||||
@ -46,11 +46,9 @@ QueuedTcpServerThread::~QueuedTcpServerThread()
|
||||
}
|
||||
|
||||
|
||||
QByteArrayList QueuedTcpServerThread::defaultResponse(const int code,
|
||||
const QVariantHash &json)
|
||||
QByteArrayList QueuedTcpServerThread::defaultResponse(const int code, const QVariantHash &json)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Build server response with code" << code
|
||||
<< "and json";
|
||||
qCDebug(LOG_SERV) << "Build server response with code" << code << "and json";
|
||||
|
||||
QList<QByteArray> output;
|
||||
output += "HTTP/1.1 " + QByteArray::number(code) + " "
|
||||
@ -58,8 +56,7 @@ QByteArrayList QueuedTcpServerThread::defaultResponse(const int code,
|
||||
output += "Server: QueuedServer/Qt" + QByteArray(qVersion()) + "\r\n";
|
||||
output += "Date: "
|
||||
+ QLocale::c()
|
||||
.toString(QDateTime::currentDateTimeUtc(),
|
||||
"ddd, d MMM yyyy HH:mm:dd t")
|
||||
.toString(QDateTime::currentDateTimeUtc(), "ddd, d MMM yyyy HH:mm:dd t")
|
||||
.toUtf8()
|
||||
+ "\r\n";
|
||||
output += "Content-Type: application/json\r\n";
|
||||
@ -68,8 +65,7 @@ QByteArrayList QueuedTcpServerThread::defaultResponse(const int code,
|
||||
// json response
|
||||
if (!json.isEmpty()) {
|
||||
auto jsonObj = QJsonObject::fromVariantHash(json);
|
||||
auto jsonByte
|
||||
= QJsonDocument(jsonObj).toJson(QJsonDocument::JsonFormat::Compact);
|
||||
auto jsonByte = QJsonDocument(jsonObj).toJson(QJsonDocument::JsonFormat::Compact);
|
||||
output += jsonByte;
|
||||
}
|
||||
|
||||
@ -97,17 +93,16 @@ QueuedTcpServerThread::getHeaders(const QStringList &headers)
|
||||
if (parsed.count() < 2)
|
||||
continue;
|
||||
headersObj.headers += QPair<QByteArray, QByteArray>(
|
||||
{parsed.first().toUtf8().toLower(),
|
||||
parsed.mid(1).join(": ").toUtf8()});
|
||||
{parsed.first().toUtf8().toLower(), parsed.mid(1).join(": ").toUtf8()});
|
||||
}
|
||||
|
||||
return headersObj;
|
||||
}
|
||||
|
||||
|
||||
QueuedTcpServerThread::QueuedTcpServerRequest QueuedTcpServerThread::getRequest(
|
||||
const QByteArray &body,
|
||||
const QueuedTcpServerThread::QueuedTcpServerHeaders &headers)
|
||||
QueuedTcpServerThread::QueuedTcpServerRequest
|
||||
QueuedTcpServerThread::getRequest(const QByteArray &body,
|
||||
const QueuedTcpServerThread::QueuedTcpServerHeaders &headers)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Get request object from body" << body;
|
||||
|
||||
@ -159,8 +154,7 @@ QueuedTcpServerThread::response(const QueuedTcpServerRequest &request) const
|
||||
netRequest.setRawHeader(headers.first, headers.second);
|
||||
|
||||
// prepend code
|
||||
if (netRequest.header(QNetworkRequest::KnownHeaders::ContentTypeHeader)
|
||||
.toString()
|
||||
if (netRequest.header(QNetworkRequest::KnownHeaders::ContentTypeHeader).toString()
|
||||
!= "application/json")
|
||||
response.code = 415;
|
||||
else
|
||||
@ -169,12 +163,10 @@ QueuedTcpServerThread::response(const QueuedTcpServerRequest &request) const
|
||||
|
||||
// json data
|
||||
if (response.code == 200) {
|
||||
auto req = QueuedTcpServerResponseHelper::parsePath(
|
||||
request.headers.query.path());
|
||||
auto req = QueuedTcpServerResponseHelper::parsePath(request.headers.query.path());
|
||||
req.type = request.headers.request;
|
||||
if (req.valid) {
|
||||
response.data = QueuedTcpServerResponseHelper::getData(
|
||||
req, request.data, token);
|
||||
response.data = QueuedTcpServerResponseHelper::getData(req, request.data, token);
|
||||
response.code = response.data["code"].toInt();
|
||||
} else {
|
||||
response.code = 404;
|
||||
@ -193,8 +185,7 @@ void QueuedTcpServerThread::run()
|
||||
return;
|
||||
}
|
||||
|
||||
connect(m_socket, SIGNAL(readyRead()), this, SLOT(readyRead()),
|
||||
Qt::DirectConnection);
|
||||
connect(m_socket, SIGNAL(readyRead()), this, SLOT(readyRead()), Qt::DirectConnection);
|
||||
|
||||
exec();
|
||||
}
|
||||
|
@ -44,16 +44,13 @@ public:
|
||||
QVariantHash data;
|
||||
} QueuedTcpServerResponse;
|
||||
|
||||
explicit QueuedTcpServerThread(int socketDescriptor, const int timeout,
|
||||
QObject *parent);
|
||||
explicit QueuedTcpServerThread(int socketDescriptor, const int timeout, QObject *parent);
|
||||
virtual ~QueuedTcpServerThread();
|
||||
static QByteArrayList defaultResponse(const int code,
|
||||
const QVariantHash &json);
|
||||
static QByteArrayList defaultResponse(const int code, const QVariantHash &json);
|
||||
static QueuedTcpServerHeaders getHeaders(const QStringList &headers);
|
||||
static QueuedTcpServerRequest
|
||||
getRequest(const QByteArray &body, const QueuedTcpServerHeaders &headers);
|
||||
QueuedTcpServerResponse
|
||||
response(const QueuedTcpServerRequest &request) const;
|
||||
static QueuedTcpServerRequest getRequest(const QByteArray &body,
|
||||
const QueuedTcpServerHeaders &headers);
|
||||
QueuedTcpServerResponse response(const QueuedTcpServerRequest &request) const;
|
||||
void run() override;
|
||||
|
||||
private slots:
|
||||
|
@ -50,8 +50,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
// parser
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription(
|
||||
"Daemon for starting jobs to queue of calculations");
|
||||
parser.setApplicationDescription("Daemon for starting jobs to queue of calculations");
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
// info
|
||||
|
Reference in New Issue
Block a user