diff --git a/CMakeLists.txt b/CMakeLists.txt index fb4f637..c83979b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/SMSubProcess.cpp b/SMSubProcess.cpp index 63c7575..9a67656 100644 --- a/SMSubProcess.cpp +++ b/SMSubProcess.cpp @@ -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::of(&QProcess::finished), [=](int exitCode) { + QObject::connect(&process, QOverload::of(&QProcess::finished), this, [=](int exitCode) { // Exit with the same exit code as the process emit processStopped(); QCoreApplication::exit(exitCode); diff --git a/SMSubProcess.h b/SMSubProcess.h index d4462ca..dedd81c 100644 --- a/SMSubProcess.h +++ b/SMSubProcess.h @@ -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: diff --git a/SMSubServer.cpp b/SMSubServer.cpp index 25dfd74..962829a 100644 --- a/SMSubServer.cpp +++ b/SMSubServer.cpp @@ -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::const_iterator it = sockets.constBegin(); - QVector::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); }); } diff --git a/SMSubServer.h b/SMSubServer.h index 706612f..f5f9936 100644 --- a/SMSubServer.h +++ b/SMSubServer.h @@ -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: diff --git a/main.cpp b/main.cpp index c117d86..1baf24b 100644 --- a/main.cpp +++ b/main.cpp @@ -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 { diff --git a/smsub.h b/smsub.h index fcd1788..d05e8bc 100644 --- a/smsub.h +++ b/smsub.h @@ -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: diff --git a/smsub.pro b/smsub.pro index 7fea340..6622b2b 100644 --- a/smsub.pro +++ b/smsub.pro @@ -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: