1 | /* |
---|---|
2 | This file is part of the KDE libraries |
3 | SPDX-FileCopyrightText: 2007 Andreas Hartmetz <ahartmetz@gmail.com> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | |
8 | #ifndef KSSLD_DBUSMETATYPES_H |
9 | #define KSSLD_DBUSMETATYPES_H |
10 | |
11 | #include "ksslcertificatemanager_p.h" |
12 | |
13 | #include <QDBusArgument> |
14 | #include <QDBusMetaType> |
15 | #include <qglobal.h> |
16 | |
17 | Q_DECLARE_METATYPE(KSslCertificateRule) |
18 | Q_DECLARE_METATYPE(QSslError::SslError) |
19 | |
20 | inline QDBusArgument &operator<<(QDBusArgument &argument, const QSslCertificate &cert) |
21 | { |
22 | argument.beginStructure(); |
23 | argument << cert.toDer(); |
24 | argument.endStructure(); |
25 | return argument; |
26 | } |
27 | |
28 | inline const QDBusArgument &operator>>(const QDBusArgument &argument, QSslCertificate &cert) |
29 | { |
30 | QByteArray data; |
31 | argument.beginStructure(); |
32 | argument >> data; |
33 | argument.endStructure(); |
34 | cert = QSslCertificate(data, QSsl::Der); |
35 | return argument; |
36 | } |
37 | |
38 | inline QDBusArgument &operator<<(QDBusArgument &argument, const KSslCertificateRule &rule) |
39 | { |
40 | argument.beginStructure(); |
41 | argument << rule.certificate() << rule.hostName() << rule.isRejected() << rule.expiryDateTime().toString(format: Qt::ISODate) << rule.ignoredErrors(); |
42 | argument.endStructure(); |
43 | return argument; |
44 | } |
45 | |
46 | inline const QDBusArgument &operator>>(const QDBusArgument &argument, KSslCertificateRule &rule) |
47 | { |
48 | QSslCertificate cert; |
49 | QString hostName; |
50 | bool isRejected; |
51 | QString expiryStr; |
52 | QList<QSslError::SslError> ignoredErrors; |
53 | argument.beginStructure(); |
54 | argument >> cert >> hostName >> isRejected >> expiryStr >> ignoredErrors; |
55 | argument.endStructure(); |
56 | |
57 | KSslCertificateRule ret(cert, hostName); |
58 | ret.setRejected(isRejected); |
59 | ret.setExpiryDateTime(QDateTime::fromString(string: expiryStr, format: Qt::ISODate)); |
60 | ret.setIgnoredErrors(ignoredErrors); |
61 | rule = ret; |
62 | return argument; |
63 | } |
64 | |
65 | inline QDBusArgument &operator<<(QDBusArgument &argument, const QSslError::SslError &error) |
66 | { |
67 | argument.beginStructure(); // overhead ho! |
68 | argument << static_cast<int>(error); |
69 | argument.endStructure(); |
70 | return argument; |
71 | } |
72 | |
73 | inline const QDBusArgument &operator>>(const QDBusArgument &argument, QSslError::SslError &error) |
74 | { |
75 | int data; |
76 | argument.beginStructure(); |
77 | argument >> data; |
78 | argument.endStructure(); |
79 | error = static_cast<QSslError::SslError>(data); |
80 | return argument; |
81 | } |
82 | |
83 | static void registerMetaTypesForKSSLD() |
84 | { |
85 | qDBusRegisterMetaType<QSslCertificate>(); |
86 | qDBusRegisterMetaType<KSslCertificateRule>(); |
87 | qDBusRegisterMetaType<QList<QSslCertificate>>(); |
88 | qDBusRegisterMetaType<QSslError::SslError>(); |
89 | qDBusRegisterMetaType<QList<QSslError::SslError>>(); |
90 | } |
91 | |
92 | #endif // KSSLD_DBUSMETATYPES_H |
93 |