diff --git a/CMakeLists.txt b/CMakeLists.txt index f4360b49..01a8b48c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,95 +1,92 @@ cmake_minimum_required(VERSION 3.0) project(drkonqi) set(PROJECT_VERSION "5.18.80") set(PROJECT_VERSION_MAJOR 5) set(QT_MIN_VERSION "5.14.0") set(KF5_MIN_VERSION "5.69.0") find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) include(KDEInstallDirs) include(KDECMakeSettings) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(ECMQtDeclareLoggingCategory) include(ECMAddTests) include(ECMMarkAsTest) include(CheckFunctionExists) include(FeatureSummary) include(KDEClangFormat) kde_enable_exceptions() find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Widgets Test DBus Concurrent) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS I18n CoreAddons Service ConfigWidgets JobWidgets KIO Crash Completion WidgetsAddons Wallet Notifications IdleTime WindowSystem SyntaxHighlighting) find_package(Qt5X11Extras ${QT_MIN_VERSION} CONFIG) set_package_properties(Qt5X11Extras PROPERTIES TYPE RECOMMENDED PURPOSE "Recommended for better integration on X11.") if (MINGW) find_package(ZLIB REQUIRED) find_library(INTL_LIBRARY NAMES intl) find_library(IBERTY_LIBRARY NAMES iberty) find_library(BFD_LIBRARY NAMES bfd) if (IBERTY_LIBRARY) set(iberty_FOUND 1) else() set(msg "iberty") endif() if (BFD_LIBRARY) set(bfd_FOUND 1) else() set(msg "${msg} bfd") endif() if (INTL_LIBRARY) set(intl_FOUND 1) else() set(msg "${msg} intl") endif() if (msg) message(FATAL_ERROR "could not find ${msg}") endif() add_library(intl SHARED IMPORTED) set_target_properties(intl PROPERTIES IMPORTED_IMPLIB ${INTL_LIBRARY} ) add_library(iberty STATIC IMPORTED) set_target_properties(iberty PROPERTIES IMPORTED_LOCATION ${IBERTY_LIBRARY} ) add_library(bfd STATIC IMPORTED) set_target_properties(bfd PROPERTIES IMPORTED_LOCATION ${BFD_LIBRARY} # bfd header requires this to be defined INTERFACE_COMPILE_DEFINITIONS "PACKAGE;PACKAGE_VERSION" ) find_path(BFD_INCLUDE_DIR bfd.h) include_directories(${BFD_INCLUDE_DIR}) endif() include_directories("${CMAKE_CURRENT_BINARY_DIR}") -if (EXISTS "${CMAKE_SOURCE_DIR}/.git") - add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000) -endif() add_subdirectory(src) # add clang-format target for all our real source files file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h) kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES}) install(FILES drkonqi.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR}) if (${ECM_VERSION} STRGREATER "5.58.0") install(FILES drkonqi.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR}) else() install(FILES drkonqi.categories DESTINATION ${KDE_INSTALL_CONFDIR}) endif() feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/bugzillaintegration/libbugzilla/apijob.cpp b/src/bugzillaintegration/libbugzilla/apijob.cpp index 4ce6a28d..4a142c8f 100644 --- a/src/bugzillaintegration/libbugzilla/apijob.cpp +++ b/src/bugzillaintegration/libbugzilla/apijob.cpp @@ -1,141 +1,145 @@ /* Copyright 2019 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "apijob.h" #include #include #include #include "bugzilla_debug.h" #include "exceptions.h" namespace Bugzilla { TransferAPIJob::TransferAPIJob(KIO::TransferJob *transferJob, QObject *parent) : APIJob(parent) , m_transferJob(transferJob) { // Required for every request type. addMetaData(QStringLiteral("content-type"), QStringLiteral("application/json")); addMetaData(QStringLiteral("accept"), QStringLiteral("application/json")); addMetaData(QStringLiteral("UserAgent"), QStringLiteral("DrKonqi")); // We don't want HTML blobs but proper job errors + text! addMetaData(QStringLiteral("errorPage"), QStringLiteral("false")); + // Disable automatic cookie injection. We don't need cookies but they + // can mess up requests (supposedly by being unexpected or invalid or outdated ...) + // https://bugs.kde.org/show_bug.cgi?id=419646 + addMetaData(QStringLiteral("cookies"), QStringLiteral("none")); connect(m_transferJob, &KIO::TransferJob::data, this, [this](KIO::Job *, const QByteArray &data) { m_data += data; }); connect(m_transferJob, &KIO::TransferJob::finished, this, [this](KJob *job) { // Set errors, they are read by document() when the consumer reads // the data and possibly raised as exception. setError(job->error()); setErrorText(job->errorText()); Q_ASSERT(!((KIO::TransferJob*)job)->isErrorPage()); // Force a delay on all API actions if configured. This allows // simulation of slow connections. static int delay = qEnvironmentVariableIntValue("DRKONQI_HTTP_DELAY_MS"); if (delay > 0) { QTimer::singleShot(delay, [this] { emitResult(); }); return; } emitResult(); }); } void TransferAPIJob::addMetaData(const QString &key, const QString &value) { m_transferJob->addMetaData(key, value); } void TransferAPIJob::setPutData(const QByteArray &data) { m_putData = data; // This is really awkward, does it need to be this way? Why can't we just // push the entire array in? // dataReq says we shouldn't send data >1mb, so segment the incoming data // accordingly and generate QBAs wrapping the raw data (zero-copy). int segmentSize = 1024 * 1024; // 1 mb per segment maximum int segments = qMax(data.size() / segmentSize, 1); m_dataSegments.reserve(segments); for (int i = 0; i < segments; ++i) { int offset = i * segmentSize; const char *buf = data.constData() + offset; int segmentLength = qMin(offset + segmentSize, data.size()); m_dataSegments.append(QByteArray::fromRawData(buf, segmentLength)); } // TODO: throw away, only here to make sure I don't mess up the // segmentation. int allLengths = 0; for (const auto &a : qAsConst(m_dataSegments)) { allLengths += a.size(); } Q_ASSERT(allLengths == data.size()); connect(m_transferJob, &KIO::TransferJob::dataReq, this, [this](KIO::Job *, QByteArray &dataForSending) { if (m_dataSegments.isEmpty()) { return; } dataForSending = m_dataSegments.takeFirst(); }); } QJsonDocument APIJob::document() const { ProtocolException::maybeThrow(this); Q_ASSERT(error() == KJob::NoError); auto document = QJsonDocument::fromJson(data()); APIException::maybeThrow(document); return document; } QJsonObject APIJob::object() const { return document().object(); } void APIJob::setAutoStart(bool start) { m_autostart = start; } void APIJob::connectNotify(const QMetaMethod &signal) { if (m_autostart && signal == QMetaMethod::fromSignal(&KJob::finished)) { qCDebug(BUGZILLA_LOG) << "auto starting"; start(); } KJob::connectNotify(signal); } } // namespace Bugzilla