| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | // Qt-Security score:significant reason:default |
| 4 | |
| 5 | #ifndef QDBUSINTROSPECTION_P_H |
| 6 | #define QDBUSINTROSPECTION_P_H |
| 7 | |
| 8 | // |
| 9 | // W A R N I N G |
| 10 | // ------------- |
| 11 | // |
| 12 | // This file is not part of the Qt API. It exists for the convenience |
| 13 | // of the QLibrary class. This header file may change from |
| 14 | // version to version without notice, or even be removed. |
| 15 | // |
| 16 | // We mean it. |
| 17 | // |
| 18 | |
| 19 | #include <QtDBus/private/qtdbusglobal_p.h> |
| 20 | #include <QtCore/qlist.h> |
| 21 | #include <QtCore/qmap.h> |
| 22 | #include <QtCore/qshareddata.h> |
| 23 | #include <QtCore/qstring.h> |
| 24 | #include <QtCore/qstringlist.h> |
| 25 | |
| 26 | #ifndef QT_NO_DBUS |
| 27 | |
| 28 | QT_BEGIN_NAMESPACE |
| 29 | |
| 30 | class Q_DBUS_EXPORT QDBusIntrospection |
| 31 | { |
| 32 | public: |
| 33 | // forward declarations |
| 34 | struct Argument; |
| 35 | struct Method; |
| 36 | struct Signal; |
| 37 | struct Property; |
| 38 | struct Interface; |
| 39 | struct Object; |
| 40 | struct ObjectTree; |
| 41 | struct Annotation; |
| 42 | |
| 43 | // typedefs |
| 44 | typedef QMap<QString, Annotation> Annotations; |
| 45 | typedef QList<Argument> Arguments; |
| 46 | typedef QMultiMap<QString, Method> Methods; |
| 47 | typedef QMultiMap<QString, Signal> Signals; |
| 48 | typedef QMap<QString, Property> Properties; |
| 49 | typedef QMap<QString, QSharedDataPointer<Interface> > Interfaces; |
| 50 | typedef QMap<QString, QSharedDataPointer<ObjectTree> > Objects; |
| 51 | |
| 52 | public: |
| 53 | // the structs |
| 54 | |
| 55 | // Line and column numbers have the same meaning as in QXmlStreamReader. |
| 56 | struct SourceLocation |
| 57 | { |
| 58 | qint64 lineNumber = 1; |
| 59 | qint64 columnNumber = 0; |
| 60 | }; |
| 61 | |
| 62 | class Q_DBUS_EXPORT DiagnosticsReporter |
| 63 | { |
| 64 | Q_DISABLE_COPY_MOVE(DiagnosticsReporter) |
| 65 | public: |
| 66 | DiagnosticsReporter() = default; |
| 67 | virtual ~DiagnosticsReporter(); |
| 68 | virtual void warning(const SourceLocation &location, const char *msg, ...) |
| 69 | Q_ATTRIBUTE_FORMAT_PRINTF(3, 4) = 0; |
| 70 | virtual void error(const SourceLocation &location, const char *msg, ...) |
| 71 | Q_ATTRIBUTE_FORMAT_PRINTF(3, 4) = 0; |
| 72 | }; |
| 73 | |
| 74 | struct Annotation |
| 75 | { |
| 76 | SourceLocation location; |
| 77 | QString name; |
| 78 | QString value; |
| 79 | |
| 80 | inline bool operator==(const Annotation &other) const |
| 81 | { |
| 82 | return name == other.name && value == other.value; |
| 83 | } |
| 84 | }; |
| 85 | |
| 86 | struct Argument |
| 87 | { |
| 88 | SourceLocation location; |
| 89 | QString type; |
| 90 | QString name; |
| 91 | |
| 92 | inline bool operator==(const Argument& other) const |
| 93 | { return name == other.name && type == other.type; } |
| 94 | }; |
| 95 | |
| 96 | struct Method |
| 97 | { |
| 98 | SourceLocation location; |
| 99 | QString name; |
| 100 | Arguments inputArgs; |
| 101 | Arguments outputArgs; |
| 102 | Annotations annotations; |
| 103 | |
| 104 | inline bool operator==(const Method& other) const |
| 105 | { return name == other.name && annotations == other.annotations && |
| 106 | inputArgs == other.inputArgs && outputArgs == other.outputArgs; } |
| 107 | }; |
| 108 | |
| 109 | struct Signal |
| 110 | { |
| 111 | SourceLocation location; |
| 112 | QString name; |
| 113 | Arguments outputArgs; |
| 114 | Annotations annotations; |
| 115 | |
| 116 | inline bool operator==(const Signal& other) const |
| 117 | { return name == other.name && annotations == other.annotations && |
| 118 | outputArgs == other.outputArgs; } |
| 119 | }; |
| 120 | |
| 121 | struct Property |
| 122 | { |
| 123 | enum Access { Read, Write, ReadWrite }; |
| 124 | SourceLocation location; |
| 125 | QString name; |
| 126 | QString type; |
| 127 | Access access; |
| 128 | Annotations annotations; |
| 129 | |
| 130 | inline bool operator==(const Property& other) const |
| 131 | { return access == other.access && name == other.name && |
| 132 | annotations == other.annotations && type == other.type; } |
| 133 | }; |
| 134 | |
| 135 | struct Interface: public QSharedData |
| 136 | { |
| 137 | SourceLocation location; |
| 138 | QString name; |
| 139 | QString introspection; |
| 140 | |
| 141 | Annotations annotations; |
| 142 | Methods methods; |
| 143 | Signals signals_; |
| 144 | Properties properties; |
| 145 | |
| 146 | inline bool operator==(const Interface &other) const |
| 147 | { return !name.isEmpty() && name == other.name; } |
| 148 | }; |
| 149 | |
| 150 | struct Object: public QSharedData |
| 151 | { |
| 152 | SourceLocation location; |
| 153 | QString service; |
| 154 | QString path; |
| 155 | |
| 156 | QStringList interfaces; |
| 157 | QStringList childObjects; |
| 158 | }; |
| 159 | |
| 160 | public: |
| 161 | static Interface parseInterface(const QString &xml, DiagnosticsReporter *reporter = nullptr); |
| 162 | static Interfaces parseInterfaces(const QString &xml, DiagnosticsReporter *reporter = nullptr); |
| 163 | static Object parseObject(const QString &xml, const QString &service = QString(), |
| 164 | const QString &path = QString(), |
| 165 | DiagnosticsReporter *reporter = nullptr); |
| 166 | |
| 167 | private: |
| 168 | QDBusIntrospection(); |
| 169 | }; |
| 170 | |
| 171 | QT_END_NAMESPACE |
| 172 | |
| 173 | #endif // QT_NO_DBUS |
| 174 | #endif |
| 175 | |