From c8d8046412467d10abd439bf2066b2304122d7c6 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Tue, 27 Dec 2022 17:04:42 +0100 Subject: refactor: add logging category for credentials Signed-off-by: Sefa Eyeoglu --- libraries/katabasis/include/katabasis/DeviceFlow.h | 3 +++ libraries/katabasis/src/DeviceFlow.cpp | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'libraries') diff --git a/libraries/katabasis/include/katabasis/DeviceFlow.h b/libraries/katabasis/include/katabasis/DeviceFlow.h index b68c92e0..a5bfbbf3 100644 --- a/libraries/katabasis/include/katabasis/DeviceFlow.h +++ b/libraries/katabasis/include/katabasis/DeviceFlow.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -11,6 +12,8 @@ namespace Katabasis { +Q_DECLARE_LOGGING_CATEGORY(katabasisCredentials) + class ReplyServer; class PollServer; diff --git a/libraries/katabasis/src/DeviceFlow.cpp b/libraries/katabasis/src/DeviceFlow.cpp index f78fd620..17ee379b 100644 --- a/libraries/katabasis/src/DeviceFlow.cpp +++ b/libraries/katabasis/src/DeviceFlow.cpp @@ -22,6 +22,7 @@ #include "JsonResponse.h" namespace { + // ref: https://tools.ietf.org/html/rfc8628#section-3.2 // Exception: Google sign-in uses "verification_url" instead of "*_uri" - we'll accept both. bool hasMandatoryDeviceAuthParams(const QVariantMap& params) @@ -58,6 +59,8 @@ QByteArray createQueryParameters(const QList ¶m namespace Katabasis { +Q_LOGGING_CATEGORY(katabasisCredentials, "katabasis.credentials", QtWarningMsg) + DeviceFlow::DeviceFlow(Options & opts, Token & token, QObject *parent, QNetworkAccessManager *manager) : QObject(parent), token_(token) { manager_ = manager ? manager : new QNetworkAccessManager(this); qRegisterMetaType("QNetworkReply::NetworkError"); @@ -333,9 +336,7 @@ QString DeviceFlow::refreshToken() { } void DeviceFlow::setRefreshToken(const QString &v) { -#ifndef NDEBUG - qDebug() << "DeviceFlow::setRefreshToken" << v << "..."; -#endif + qCDebug(katabasisCredentials) << "new refresh token:" << v; token_.refresh_token = v; } -- cgit From f33f596584bf88df36175516764d5d7977d98b98 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Tue, 27 Dec 2022 17:23:44 +0100 Subject: refactor: use ECM logging categories instead Co-authored-by: flow Signed-off-by: Sefa Eyeoglu --- CMakeLists.txt | 2 ++ launcher/CMakeLists.txt | 13 ++++++++++-- launcher/Logging.cpp | 22 -------------------- launcher/Logging.h | 24 ---------------------- libraries/katabasis/CMakeLists.txt | 9 ++++++++ libraries/katabasis/include/katabasis/DeviceFlow.h | 2 -- libraries/katabasis/src/DeviceFlow.cpp | 3 +-- 7 files changed, 23 insertions(+), 52 deletions(-) delete mode 100644 launcher/Logging.cpp delete mode 100644 launcher/Logging.h (limited to 'libraries') diff --git a/CMakeLists.txt b/CMakeLists.txt index de9b6fe1..c7ba9e9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -268,6 +268,8 @@ if(NOT Launcher_FORCE_BUNDLED_LIBS) find_package(ghc_filesystem QUIET) endif() +include(ECMQtDeclareLoggingCategory) + ####################################### Program Info ####################################### set(Launcher_APP_BINARY_NAME "prismlauncher" CACHE STRING "Name of the Launcher binary") diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 21597081..4057c876 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -27,8 +27,6 @@ set(CORE_SOURCES StringUtils.h StringUtils.cpp RuntimeContext.h - Logging.h - Logging.cpp # Basic instance manipulation tasks (derived from InstanceTask) InstanceCreationTask.h @@ -553,6 +551,17 @@ set(ATLAUNCHER_SOURCES modplatform/atlauncher/ATLShareCode.h ) +######## Logging categories ######## + +ecm_qt_declare_logging_category(CORE_SOURCES + HEADER Logging.h + IDENTIFIER authCredentials + CATEGORY_NAME "launcher.auth.credentials" + DEFAULT_SEVERITY Warning + DESCRIPTION "Secrets and credentials for debugging purposes" + EXPORT "${Launcher_Name}" +) + ################################ COMPILE ################################ set(LOGIC_SOURCES diff --git a/launcher/Logging.cpp b/launcher/Logging.cpp deleted file mode 100644 index d0e30473..00000000 --- a/launcher/Logging.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -/* - * PolyMC - Minecraft Launcher - * Copyright (C) 2022 Sefa Eyeoglu - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "Logging.h" - -Q_LOGGING_CATEGORY(authCredentials, "launcher.auth.credentials", QtWarningMsg) diff --git a/launcher/Logging.h b/launcher/Logging.h deleted file mode 100644 index 0fcb30b7..00000000 --- a/launcher/Logging.h +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -/* - * PolyMC - Minecraft Launcher - * Copyright (C) 2022 Sefa Eyeoglu - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#pragma once - -#include - -Q_DECLARE_LOGGING_CATEGORY(authCredentials) diff --git a/libraries/katabasis/CMakeLists.txt b/libraries/katabasis/CMakeLists.txt index f764feb6..643244ed 100644 --- a/libraries/katabasis/CMakeLists.txt +++ b/libraries/katabasis/CMakeLists.txt @@ -38,6 +38,15 @@ set( katabasis_PUBLIC include/katabasis/RequestParameter.h ) +ecm_qt_declare_logging_category(katabasis_PRIVATE + HEADER KatabasisLogging.h # NOTE: this won't be in src/, but CMAKE_BINARY_DIR/src isn't included by default so this should be fine + IDENTIFIER katabasisCredentials + CATEGORY_NAME "katabasis.credentials" + DEFAULT_SEVERITY Warning + DESCRIPTION "Secrets and credentials from Katabasis" + EXPORT "Katabasis" +) + add_library( Katabasis STATIC ${katabasis_PRIVATE} ${katabasis_PUBLIC} ) target_link_libraries(Katabasis Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Network) diff --git a/libraries/katabasis/include/katabasis/DeviceFlow.h b/libraries/katabasis/include/katabasis/DeviceFlow.h index a5bfbbf3..0401df3c 100644 --- a/libraries/katabasis/include/katabasis/DeviceFlow.h +++ b/libraries/katabasis/include/katabasis/DeviceFlow.h @@ -12,8 +12,6 @@ namespace Katabasis { -Q_DECLARE_LOGGING_CATEGORY(katabasisCredentials) - class ReplyServer; class PollServer; diff --git a/libraries/katabasis/src/DeviceFlow.cpp b/libraries/katabasis/src/DeviceFlow.cpp index 17ee379b..f49fcb7d 100644 --- a/libraries/katabasis/src/DeviceFlow.cpp +++ b/libraries/katabasis/src/DeviceFlow.cpp @@ -19,6 +19,7 @@ #include "katabasis/PollServer.h" #include "katabasis/Globals.h" +#include "KatabasisLogging.h" #include "JsonResponse.h" namespace { @@ -59,8 +60,6 @@ QByteArray createQueryParameters(const QList ¶m namespace Katabasis { -Q_LOGGING_CATEGORY(katabasisCredentials, "katabasis.credentials", QtWarningMsg) - DeviceFlow::DeviceFlow(Options & opts, Token & token, QObject *parent, QNetworkAccessManager *manager) : QObject(parent), token_(token) { manager_ = manager ? manager : new QNetworkAccessManager(this); qRegisterMetaType("QNetworkReply::NetworkError"); -- cgit