File indexing completed on 2024-11-03 11:08:36
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 Coredump::Coredump(QByteArray cursor, EntriesHash data) 0009 : m_cursor(std::move(cursor)) 0010 , m_rawData(std::move(data)) 0011 , uid(m_rawData[QByteArrayLiteral("COREDUMP_UID")].toInt()) 0012 , pid(m_rawData[QByteArrayLiteral("COREDUMP_PID")].toInt()) 0013 , exe(QString::fromLocal8Bit(m_rawData[QByteArrayLiteral("COREDUMP_EXE")])) 0014 , filename(QString::fromLocal8Bit(m_rawData[keyFilename()])) 0015 , systemd_unit(QString::fromLocal8Bit(m_rawData[QByteArrayLiteral("_SYSTEMD_UNIT")])) 0016 { 0017 } 0018 0019 Coredump::Coredump(const QJsonDocument &document) 0020 : Coredump(QByteArray() /* not from journal, has no cursor */, documentToHash(document)) 0021 { 0022 } 0023 0024 QByteArray Coredump::keyFilename() 0025 { 0026 return QByteArrayLiteral("COREDUMP_FILENAME"); 0027 } 0028 0029 Coredump::EntriesHash Coredump::documentToHash(const QJsonDocument &document) 0030 { 0031 const QVariantMap variantMap = document.toVariant().toMap(); 0032 EntriesHash hash; 0033 for (auto it = variantMap.cbegin(); it != variantMap.cend(); ++it) { 0034 hash.insert(it.key().toUtf8(), it->value<QByteArray>()); 0035 } 0036 return hash; 0037 }