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 QDBUSARGUMENT_P_H
6#define QDBUSARGUMENT_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 <qdbusargument.h>
21#include "qdbusconnection.h"
22#include "qdbusunixfiledescriptor.h"
23#include "qdbus_symbols_p.h"
24
25#ifndef QT_NO_DBUS
26
27#ifndef DBUS_TYPE_UNIX_FD
28# define DBUS_TYPE_UNIX_FD int('h')
29# define DBUS_TYPE_UNIX_FD_AS_STRING "h"
30#endif
31
32QT_BEGIN_NAMESPACE
33
34class QDBusMarshaller;
35class QDBusDemarshaller;
36class QDBusArgumentPrivate
37{
38 Q_DISABLE_COPY_MOVE(QDBusArgumentPrivate)
39public:
40 enum class Direction { Marshalling, Demarshalling };
41
42 virtual ~QDBusArgumentPrivate();
43
44 static bool checkRead(QDBusArgumentPrivate *d);
45 static bool checkReadAndDetach(QDBusArgumentPrivate *&d);
46 static bool checkWrite(QDBusArgumentPrivate *&d);
47
48 QDBusMarshaller *marshaller();
49 QDBusDemarshaller *demarshaller();
50
51 static QByteArray createSignature(QMetaType type);
52 static inline QDBusArgument create(QDBusArgumentPrivate *d)
53 {
54 QDBusArgument q(d);
55 return q;
56 }
57 static inline QDBusArgumentPrivate *d(QDBusArgument &q)
58 { return q.d; }
59
60 DBusMessage *message = nullptr;
61 QAtomicInt ref = 1;
62 QDBusConnection::ConnectionCapabilities capabilities;
63 Direction direction;
64
65protected:
66 explicit QDBusArgumentPrivate(Direction direction,
67 QDBusConnection::ConnectionCapabilities flags = {})
68 : capabilities(flags), direction(direction)
69 {
70 }
71};
72
73class QDBusMarshaller final : public QDBusArgumentPrivate
74{
75public:
76 explicit QDBusMarshaller(QDBusConnection::ConnectionCapabilities flags = {})
77 : QDBusArgumentPrivate(Direction::Marshalling, flags)
78 {
79 }
80 ~QDBusMarshaller();
81
82 QString currentSignature();
83
84 void append(uchar arg);
85 void append(bool arg);
86 void append(short arg);
87 void append(ushort arg);
88 void append(int arg);
89 void append(uint arg);
90 void append(qlonglong arg);
91 void append(qulonglong arg);
92 void append(double arg);
93 void append(const QString &arg);
94 void append(const QDBusObjectPath &arg);
95 void append(const QDBusSignature &arg);
96 void append(const QDBusUnixFileDescriptor &arg);
97 void append(const QStringList &arg);
98 void append(const QByteArray &arg);
99 bool append(const QDBusVariant &arg); // this one can fail
100
101 QDBusMarshaller *beginStructure();
102 QDBusMarshaller *endStructure();
103 QDBusMarshaller *beginArray(QMetaType id);
104 QDBusMarshaller *endArray();
105 QDBusMarshaller *beginMap(QMetaType kid, QMetaType vid);
106 QDBusMarshaller *endMap();
107 QDBusMarshaller *beginMapEntry();
108 QDBusMarshaller *endMapEntry();
109 QDBusMarshaller *beginCommon(int code, const char *signature);
110 QDBusMarshaller *endCommon();
111 void open(QDBusMarshaller &sub, int code, const char *signature);
112 void close();
113 void error(const QString &message);
114
115 bool appendVariantInternal(const QVariant &arg);
116 bool appendRegisteredType(const QVariant &arg);
117 bool appendCrossMarshalling(QDBusDemarshaller *arg);
118
119 DBusMessageIter iterator;
120 QDBusMarshaller *parent = nullptr;
121 QByteArray *ba = nullptr;
122 QString errorString;
123 char closeCode = 0;
124 bool ok = true;
125 bool skipSignature = false;
126
127private:
128 Q_DECL_COLD_FUNCTION void unregisteredTypeError(QMetaType t);
129 Q_DISABLE_COPY_MOVE(QDBusMarshaller)
130};
131
132class QDBusDemarshaller final : public QDBusArgumentPrivate
133{
134public:
135 explicit QDBusDemarshaller(QDBusConnection::ConnectionCapabilities flags = {})
136 : QDBusArgumentPrivate(Direction::Demarshalling, flags)
137 {
138 }
139 ~QDBusDemarshaller();
140
141 QString currentSignature();
142
143 uchar toByte();
144 bool toBool();
145 ushort toUShort();
146 short toShort();
147 int toInt();
148 uint toUInt();
149 qlonglong toLongLong();
150 qulonglong toULongLong();
151 double toDouble();
152 QString toString();
153 QDBusObjectPath toObjectPath();
154 QDBusSignature toSignature();
155 QDBusUnixFileDescriptor toUnixFileDescriptor();
156 QDBusVariant toVariant();
157 QStringList toStringList();
158 QByteArray toByteArray();
159
160 QDBusDemarshaller *beginStructure();
161 QDBusDemarshaller *endStructure();
162 QDBusDemarshaller *beginArray();
163 QDBusDemarshaller *endArray();
164 QDBusDemarshaller *beginMap();
165 QDBusDemarshaller *endMap();
166 QDBusDemarshaller *beginMapEntry();
167 QDBusDemarshaller *endMapEntry();
168 QDBusDemarshaller *beginCommon();
169 QDBusDemarshaller *endCommon();
170 QDBusArgument duplicate();
171 inline void close() { }
172
173 bool atEnd();
174
175 QVariant toVariantInternal();
176 QDBusArgument::ElementType currentType();
177 bool isCurrentTypeStringLike();
178
179 DBusMessageIter iterator;
180 QDBusDemarshaller *parent = nullptr;
181
182private:
183 Q_DISABLE_COPY_MOVE(QDBusDemarshaller)
184 QString toStringUnchecked();
185 QDBusObjectPath toObjectPathUnchecked();
186 QDBusSignature toSignatureUnchecked();
187 QStringList toStringListUnchecked();
188 QByteArray toByteArrayUnchecked();
189};
190
191inline QDBusMarshaller *QDBusArgumentPrivate::marshaller()
192{ return static_cast<QDBusMarshaller *>(this); }
193
194inline QDBusDemarshaller *QDBusArgumentPrivate::demarshaller()
195{ return static_cast<QDBusDemarshaller *>(this); }
196
197QT_END_NAMESPACE
198
199#endif // QT_NO_DBUS
200#endif
201

source code of qtbase/src/dbus/qdbusargument_p.h