mirror of
https://github.com/arcan1s/queued.git
synced 2025-07-15 06:45:46 +00:00
code cleanup
This commit is contained in:
@ -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>
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user