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 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 COMPONENTS Network REQUIRED) set(FORCE_QT_VERSION "" CACHE STRING "Force Qt Version")
find_package(Qt5 COMPONENTS WebSockets QUIET) 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 set(SMSUB_SOURCES
main.cpp main.cpp
@ -31,6 +36,6 @@ add_executable(smsub
${SMSUB_SOURCES} ${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) install(TARGETS smsub DESTINATION bin)

View file

@ -1,6 +1,6 @@
/***************************************************************************** /*****************************************************************************
* smsub Server Manager Subprocess * 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, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * 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 // Connect process signal handlers
QObject::connect(&process, &QProcess::readyRead, this, &SMSubProcess::readyRead); QObject::connect(&process, &QProcess::readyRead, this, &SMSubProcess::readyRead);
QObject::connect(&process, &QProcess::errorOccurred, this, &SMSubProcess::processError); 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 // Exit with the same exit code as the process
emit processStopped(); emit processStopped();
QCoreApplication::exit(exitCode); QCoreApplication::exit(exitCode);

View file

@ -1,6 +1,6 @@
/***************************************************************************** /*****************************************************************************
* smsub Server Manager Subprocess * 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, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:

View file

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

View file

@ -1,6 +1,6 @@
/***************************************************************************** /*****************************************************************************
* smsub Server Manager Subprocess * 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, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:

View file

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

View file

@ -1,6 +1,6 @@
/***************************************************************************** /*****************************************************************************
* smsub Server Manager Subprocess * 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, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:

View file

@ -1,6 +1,6 @@
############################################################################### ###############################################################################
# smsub Server Manager Subprocess # 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, # Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met: # are permitted provided that the following conditions are met: