File indexing completed on 2024-11-03 08:07:41

0001 /*
0002     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0003     SPDX-FileCopyrightText: 2019-2022 Harald Sitter <sitter@kde.org>
0004 */
0005 
0006 #include "coredump.h"
0007 
0008 using namespace Qt::StringLiterals;
0009 
0010 Coredump::Coredump(QByteArray cursor, EntriesHash data)
0011     : m_cursor(std::move(cursor))
0012     , m_rawData(std::move(data))
0013     , uid(m_rawData[QByteArrayLiteral("COREDUMP_UID")].toInt())
0014     , pid(m_rawData[QByteArrayLiteral("COREDUMP_PID")].toInt())
0015     , exe(QString::fromLocal8Bit(m_rawData[QByteArrayLiteral("COREDUMP_EXE")]))
0016     , filename(QString::fromLocal8Bit(m_rawData[keyFilename()]))
0017     , systemd_unit(QString::fromLocal8Bit(m_rawData[QByteArrayLiteral("_SYSTEMD_UNIT")]))
0018     , bootId(QString::fromUtf8(m_rawData["_BOOT_ID"_ba]))
0019     , timestamp(QString::fromUtf8(m_rawData["COREDUMP_TIMESTAMP"_ba]))
0020 {
0021     if (!m_rawData.contains(keyCursor())) {
0022         m_rawData[keyCursor()] = m_cursor; // so we can easily access it in launcher & drkonqi
0023     }
0024 }
0025 
0026 Coredump::Coredump(const QJsonDocument &document)
0027     : Coredump(QByteArray() /* not from journal, has no cursor */, documentToHash(document))
0028 {
0029 }
0030 
0031 QByteArray Coredump::keyFilename()
0032 {
0033     return QByteArrayLiteral("COREDUMP_FILENAME");
0034 }
0035 
0036 Coredump::EntriesHash Coredump::documentToHash(const QJsonDocument &document)
0037 {
0038     const QVariantMap variantMap = document.toVariant().toMap();
0039     EntriesHash hash;
0040     for (auto it = variantMap.cbegin(); it != variantMap.cend(); ++it) {
0041         hash.insert(it.key().toUtf8(), it->value<QByteArray>());
0042     }
0043     return hash;
0044 }
0045 
0046 QByteArray Coredump::keyPickup()
0047 {
0048     return "_DRKONQI_PICKUP"_ba;
0049 }
0050 
0051 QByteArray Coredump::keyCursor()
0052 {
0053     return "_DRKONQI_SD_CURSOR"_ba;
0054 }