From 5948fcd354f4a64940805ca4d066b78ac42c61f4 Mon Sep 17 00:00:00 2001 From: varjolintu Date: Sun, 3 Dec 2023 21:06:56 +0200 Subject: [PATCH] Fix compile errors --- src/sshagent/CMakeLists.txt | 18 +++++++++++++++++- src/sshagent/KeeAgentSettings.cpp | 29 +++++++++++++++-------------- src/sshagent/OpenSSHKey.cpp | 5 +++-- tests/TestCli.cpp | 10 +++++----- tests/TestTools.cpp | 4 ++-- 5 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/sshagent/CMakeLists.txt b/src/sshagent/CMakeLists.txt index 6bbb9c94d2..9f2d74d922 100644 --- a/src/sshagent/CMakeLists.txt +++ b/src/sshagent/CMakeLists.txt @@ -1,3 +1,18 @@ +# Copyright (C) 2023 KeePassXC Team +# +# 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, either version 2 or (at your option) +# version 3 of the License. +# +# 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 . + if(WITH_XC_SSHAGENT) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) @@ -13,6 +28,7 @@ if(WITH_XC_SSHAGENT) SSHAgent.cpp ) + find_package(Qt6 REQUIRED COMPONENTS Core5Compat) add_library(sshagent STATIC ${sshagent_SOURCES}) - target_link_libraries(sshagent Qt5::Core Qt5::Widgets Qt5::Network) + target_link_libraries(sshagent Qt6::Core Qt6::Core5Compat Qt6::Widgets Qt6::Network) endif() diff --git a/src/sshagent/KeeAgentSettings.cpp b/src/sshagent/KeeAgentSettings.cpp index 272fb7edf7..5beed5b937 100644 --- a/src/sshagent/KeeAgentSettings.cpp +++ b/src/sshagent/KeeAgentSettings.cpp @@ -203,7 +203,7 @@ void KeeAgentSettings::setFileName(const QString& fileName) bool KeeAgentSettings::readBool(QXmlStreamReader& reader) { reader.readNext(); - bool ret = (reader.text().startsWith("t", Qt::CaseInsensitive)); + bool ret = (reader.text().toString().startsWith("t", Qt::CaseInsensitive)); reader.readNext(); // tag end return ret; } @@ -234,37 +234,37 @@ bool KeeAgentSettings::fromXml(const QByteArray& ba) return false; } - if (reader.qualifiedName() != "EntrySettings") { + if (reader.qualifiedName().toString() != "EntrySettings") { m_error = QCoreApplication::translate("KeeAgentSettings", "Invalid KeeAgent settings file structure."); return false; } while (!reader.error() && reader.readNextStartElement()) { - if (reader.name() == "AllowUseOfSshKey") { + if (reader.name().toString() == "AllowUseOfSshKey") { m_allowUseOfSshKey = readBool(reader); - } else if (reader.name() == "AddAtDatabaseOpen") { + } else if (reader.name().toString() == "AddAtDatabaseOpen") { m_addAtDatabaseOpen = readBool(reader); - } else if (reader.name() == "RemoveAtDatabaseClose") { + } else if (reader.name().toString() == "RemoveAtDatabaseClose") { m_removeAtDatabaseClose = readBool(reader); - } else if (reader.name() == "UseConfirmConstraintWhenAdding") { + } else if (reader.name().toString() == "UseConfirmConstraintWhenAdding") { m_useConfirmConstraintWhenAdding = readBool(reader); - } else if (reader.name() == "UseLifetimeConstraintWhenAdding") { + } else if (reader.name().toString() == "UseLifetimeConstraintWhenAdding") { m_useLifetimeConstraintWhenAdding = readBool(reader); - } else if (reader.name() == "LifetimeConstraintDuration") { + } else if (reader.name().toString() == "LifetimeConstraintDuration") { m_lifetimeConstraintDuration = readInt(reader); - } else if (reader.name() == "Location") { + } else if (reader.name().toString() == "Location") { while (!reader.error() && reader.readNextStartElement()) { - if (reader.name() == "SelectedType") { + if (reader.name().toString() == "SelectedType") { reader.readNext(); m_selectedType = reader.text().toString(); reader.readNext(); - } else if (reader.name() == "AttachmentName") { + } else if (reader.name().toString() == "AttachmentName") { reader.readNext(); m_attachmentName = reader.text().toString(); reader.readNext(); - } else if (reader.name() == "SaveAttachmentToTempFile") { + } else if (reader.name().toString() == "SaveAttachmentToTempFile") { m_saveAttachmentToTempFile = readBool(reader); - } else if (reader.name() == "FileName") { + } else if (reader.name().toString() == "FileName") { reader.readNext(); m_fileName = reader.text().toString(); reader.readNext(); @@ -293,7 +293,8 @@ QByteArray KeeAgentSettings::toXml() const QXmlStreamWriter writer(&ba); // real KeeAgent can only read UTF-16 - writer.setCodec(QTextCodec::codecForName("UTF-16")); + // TODO: Set to UTF-16 + //writer.setCodec(QTextCodec::codecForName("UTF-16")); writer.setAutoFormatting(true); writer.setAutoFormattingIndent(2); diff --git a/src/sshagent/OpenSSHKey.cpp b/src/sshagent/OpenSSHKey.cpp index 9f6fae7611..1beffc8f1d 100644 --- a/src/sshagent/OpenSSHKey.cpp +++ b/src/sshagent/OpenSSHKey.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2017 Toni Spets - * Copyright (C) 2017 KeePassXC Team + * Copyright (C) 2023 KeePassXC Team * * 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 @@ -26,6 +26,7 @@ #include #include +#include #include @@ -180,7 +181,7 @@ const QString OpenSSHKey::privateKey() auto base64Key = QString::fromUtf8(sshKey.toBase64()); for (int i = 0; i < base64Key.size(); i += 70) { - out += base64Key.midRef(i, 70); + out += QStringView{base64Key}.mid(i, 70); out += "\n"; } diff --git a/tests/TestCli.cpp b/tests/TestCli.cpp index f179e6d257..3c72c5d5b6 100644 --- a/tests/TestCli.cpp +++ b/tests/TestCli.cpp @@ -685,9 +685,9 @@ void TestCli::testClip() // Password with timeout setInput("a"); // clang-format off - QFuture future = QtConcurrent::run(&clipCmd, - static_cast(&DatabaseCommand::execute), - QStringList{"clip", m_dbFile->fileName(), "/Sample Entry", "1"}); + auto future = QtConcurrent::run(static_cast(&DatabaseCommand::execute), + &clipCmd, + QStringList{"clip", m_dbFile->fileName(), "/Sample Entry", "1"}); // clang-format on QTRY_COMPARE(clipboard->text(), QString("Password")); @@ -697,8 +697,8 @@ void TestCli::testClip() // TOTP with timeout setInput("a"); - future = QtConcurrent::run(&clipCmd, - static_cast(&DatabaseCommand::execute), + future = QtConcurrent::run(static_cast(&DatabaseCommand::execute), + &clipCmd, QStringList{"clip", m_dbFile->fileName(), "/Sample Entry", "1", "-t"}); QTRY_VERIFY(isTotp(clipboard->text())); diff --git a/tests/TestTools.cpp b/tests/TestTools.cpp index 56b3e593bf..b0f0997419 100644 --- a/tests/TestTools.cpp +++ b/tests/TestTools.cpp @@ -221,11 +221,11 @@ void TestTools::testConvertToRegex_data() << "^(?:" + Tools::escapeRegex(input) + ")$"; // Exact match does not escape the pattern - QTest::newRow("Exact Match") << input << static_cast(Tools::RegexConvertOpts::EXACT_MATCH) + QTest::newRow("Exact Match 1") << input << static_cast(Tools::RegexConvertOpts::EXACT_MATCH) << QString(R"(^(?:te|st*t?[5]^(test);',.)$)"); // Exact match with improper regex - QTest::newRow("Exact Match") << ")av(" << static_cast(Tools::RegexConvertOpts::EXACT_MATCH) + QTest::newRow("Exact Match 2") << ")av(" << static_cast(Tools::RegexConvertOpts::EXACT_MATCH) << QString(R"(^(?:)av()$)"); QTest::newRow("Exact Match & Wildcard")