Quality of Life improvements

This commit is contained in:
Syping 2021-07-07 23:47:24 +02:00
parent d2aed1ef6e
commit 60f3937b7b
8 changed files with 23 additions and 25 deletions

View file

@ -11,8 +11,13 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 COMPONENTS Network REQUIRED)
find_package(Qt5 COMPONENTS WebSockets QUIET)
set(FORCE_QT_VERSION "" CACHE STRING "Force Qt Version")
if(FORCE_QT_VERSION)
set(QT_VERSION_MAJOR ${FORCE_QT_VERSION})
else()
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
endif()
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Network WebSockets REQUIRED)
set(SMSUB_SOURCES
main.cpp
@ -31,6 +36,6 @@ add_executable(smsub
${SMSUB_SOURCES}
)
target_link_libraries(smsub PRIVATE Qt5::Network Qt5::WebSockets)
target_link_libraries(smsub PRIVATE Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::WebSockets)
install(TARGETS smsub DESTINATION bin)

View file

@ -1,6 +1,6 @@
/*****************************************************************************
* smsub Server Manager Subprocess
* Copyright (C) 2020 Syping
* Copyright (C) 2020-2021 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@ -36,7 +36,7 @@ SMSubProcess::SMSubProcess(const QString &executable, const QStringList &argumen
// Connect process signal handlers
QObject::connect(&process, &QProcess::readyRead, this, &SMSubProcess::readyRead);
QObject::connect(&process, &QProcess::errorOccurred, this, &SMSubProcess::processError);
QObject::connect(&process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), [=](int exitCode) {
QObject::connect(&process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, [=](int exitCode) {
// Exit with the same exit code as the process
emit processStopped();
QCoreApplication::exit(exitCode);

View file

@ -1,6 +1,6 @@
/*****************************************************************************
* smsub Server Manager Subprocess
* Copyright (C) 2020 Syping
* Copyright (C) 2020-2021 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:

View file

@ -1,6 +1,6 @@
/*****************************************************************************
* smsub Server Manager Subprocess
* Copyright (C) 2020 Syping
* Copyright (C) 2020-2021 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@ -91,7 +91,7 @@ void SMSubServer::newConnection()
bool SMSubServer::messageReceived(QObject *socket, const QByteArray &message)
{
// Only allow commands being sent if authenticated
bool isAuthenticated = socket->property("Authenticated").toBool();
const bool isAuthenticated = socket->property("Authenticated").toBool();
if (likely(isAuthenticated)) {
if (message.startsWith("+dbg")) {
socket->setProperty("ReceiveDbgMsg", true);
@ -145,7 +145,6 @@ bool SMSubServer::messageReceived(QObject *socket, const QByteArray &message)
// Set client as authenticated and add it to vector
socket->setProperty("Authenticated", true);
sendMessage(socket, "Login successful!\n");
isAuthenticated = true;
sockets << socket;
}
else {
@ -208,9 +207,7 @@ void SMSubServer::debugOutput(QObject *socket, const QByteArray &message)
void SMSubServer::writeOutput(const QByteArray &output)
{
// Read process output when client opted-in for log
QVector<QObject*>::const_iterator it = sockets.constBegin();
QVector<QObject*>::const_iterator end = sockets.constEnd();
while (it != end) {
for (auto it = sockets.constBegin(); it != sockets.constEnd(); it++) {
const QVariant variant = (*it)->property("ReceiveLog");
if (unlikely(variant.type() == QVariant::Bool)) {
bool receiveLog = variant.toBool();
@ -218,7 +215,6 @@ void SMSubServer::writeOutput(const QByteArray &output)
sendMessage(*it, output);
}
}
it++;
}
}
@ -238,7 +234,7 @@ void SMSubServer::registerToken(const QString &token)
{
// Register temporary token for a secure remote connection
tokens << token;
QTimer::singleShot(30000, [this, token]() {
QTimer::singleShot(30000, this, [=]() {
tokens.removeAll(token);
});
}

View file

@ -1,6 +1,6 @@
/*****************************************************************************
* smsub Server Manager Subprocess
* Copyright (C) 2020 Syping
* Copyright (C) 2020-2021 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:

View file

@ -1,6 +1,6 @@
/*****************************************************************************
* smsub Server Manager Subprocess
* Copyright (C) 2020 Syping
* Copyright (C) 2020-2021 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@ -135,7 +135,7 @@ int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
a.setApplicationName("Server Manager Subprocess");
a.setApplicationVersion("0.4");
a.setApplicationVersion("0.5");
#ifdef Q_OS_UNIX
catchUnixSignals({SIGINT, SIGHUP, SIGQUIT, SIGTERM});
@ -151,7 +151,7 @@ int main(int argc, char *argv[])
QString workingDirectory;
QStringList argumentList;
QByteArray envOnly = qgetenv("SMSUB_ENV_ONLY");
QByteArray envEnvironmentMode = qgetenv("SMSUB_ENVIRONMENT_MODE");
QByteArray envManifest = qgetenv("SMSUB_JSON");
QByteArray envExecutable = qgetenv("SMSUB_EXEC");
QByteArray envArguments = qgetenv("SMSUB_ARGS");
@ -161,7 +161,7 @@ int main(int argc, char *argv[])
QByteArray envTimeout = qgetenv("SMSUB_TIMEOUT");
QByteArray envWorkDir = qgetenv("SMSUB_WORKDIR");
if (unlikely(envOnly == "1" || envOnly.toLower() == "true")) {
if (unlikely(envEnvironmentMode == "1" || envEnvironmentMode.toLower() == "true")) {
if (likely(envExecutable.isEmpty() && envArguments.isEmpty())) {
QStringList arguments = a.arguments();
executable = arguments.takeFirst();
@ -384,11 +384,8 @@ int main(int argc, char *argv[])
const QJsonValue jsonArguments = jsonObject.value("Arguments");
if (likely(jsonArguments.isArray())) {
const QJsonArray jsonArray = jsonArguments.toArray();
QJsonArray::const_iterator it = jsonArray.constBegin();
QJsonArray::const_iterator end = jsonArray.constEnd();
while (it != end) {
for (auto it = jsonArray.constBegin(); it != jsonArray.constEnd(); it++) {
argumentList << it->toString();
it++;
}
}
else {

View file

@ -1,6 +1,6 @@
/*****************************************************************************
* smsub Server Manager Subprocess
* Copyright (C) 2020 Syping
* Copyright (C) 2020-2021 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:

View file

@ -1,6 +1,6 @@
###############################################################################
# smsub Server Manager Subprocess
# Copyright (C) 2020 Syping
# Copyright (C) 2020-2021 Syping
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met: