File indexing completed on 2024-06-02 05:21:55
0001 /* 0002 * SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> 0003 * SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 #include <KHealthCertificateParser> 0007 #include <KRecoveryCertificate> 0008 #include <KTestCertificate> 0009 #include <KVaccinationCertificate> 0010 0011 #include <QFile> 0012 #include <QMetaProperty> 0013 #include <QVariant> 0014 0015 #include <iostream> 0016 0017 static void dumpGadget(const QVariant &gadget) 0018 { 0019 const auto mo = QMetaType(gadget.userType()).metaObject(); 0020 if (!mo) { 0021 return; 0022 } 0023 0024 for (auto i = 0; i < mo->propertyCount(); ++i) { 0025 const auto prop = mo->property(i); 0026 if (!prop.isStored()) { 0027 continue; 0028 } 0029 const auto value = prop.readOnGadget(gadget.constData()); 0030 std::cout << " " << prop.name() << ": " << qPrintable(value.toString()) << std::endl; 0031 } 0032 } 0033 0034 int main(int argc, char **argv) 0035 { 0036 // TODO cli arg parsing 0037 0038 QFile in; 0039 in.open(stdin, QFile::ReadOnly); 0040 0041 const auto cert = KHealthCertificateParser::parse(in.readAll()); 0042 if (cert.isNull()) { 0043 std::cout << "unable to parse input" << std::endl; 0044 return 1; 0045 } 0046 0047 if (cert.userType() == qMetaTypeId<KVaccinationCertificate>()) { 0048 std::cout << "Vaccination certificate:" << std::endl; 0049 } else if (cert.userType() == qMetaTypeId<KTestCertificate>()) { 0050 std::cout << "Test certificate:" << std::endl; 0051 } else if (cert.userType() == qMetaTypeId<KRecoveryCertificate>()) { 0052 std::cout << "Recovery certificate:" << std::endl; 0053 } 0054 dumpGadget(cert); 0055 0056 return 0; 0057 }