Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
5 | ** | - |
6 | ** This file is part of the QtDBus module of the Qt Toolkit. | - |
7 | ** | - |
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
9 | ** Commercial License Usage | - |
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
11 | ** accordance with the commercial license agreement provided with the | - |
12 | ** Software or, alternatively, in accordance with the terms contained in | - |
13 | ** a written agreement between you and Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
16 | ** | - |
17 | ** GNU Lesser General Public License Usage | - |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
19 | ** General Public License version 2.1 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | #include "qdbusutil_p.h" | - |
43 | | - |
44 | #include "qdbus_symbols_p.h" | - |
45 | | - |
46 | #include <QtCore/qstringlist.h> | - |
47 | | - |
48 | #include "qdbusargument.h" | - |
49 | #include "qdbusunixfiledescriptor.h" | - |
50 | | - |
51 | #ifndef QT_NO_DBUS | - |
52 | | - |
53 | QT_BEGIN_NAMESPACE | - |
54 | | - |
55 | static inline bool isValidCharacterNoDash(QChar c) | - |
56 | { | - |
57 | register ushort u = c.unicode(); executed (the execution status of this line is deduced): register ushort u = c.unicode(); | - |
58 | return (u >= 'a' && u <= 'z') executed: return (u >= 'a' && u <= 'z') || (u >= 'A' && u <= 'Z') || (u >= '0' && u <= '9') || (u == '_'); Execution Count:73364 | 73364 |
59 | || (u >= 'A' && u <= 'Z') executed: return (u >= 'a' && u <= 'z') || (u >= 'A' && u <= 'Z') || (u >= '0' && u <= '9') || (u == '_'); Execution Count:73364 | 73364 |
60 | || (u >= '0' && u <= '9') executed: return (u >= 'a' && u <= 'z') || (u >= 'A' && u <= 'Z') || (u >= '0' && u <= '9') || (u == '_'); Execution Count:73364 | 73364 |
61 | || (u == '_'); executed: return (u >= 'a' && u <= 'z') || (u >= 'A' && u <= 'Z') || (u >= '0' && u <= '9') || (u == '_'); Execution Count:73364 | 73364 |
62 | } | - |
63 | | - |
64 | static inline bool isValidCharacter(QChar c) | - |
65 | { | - |
66 | register ushort u = c.unicode(); executed (the execution status of this line is deduced): register ushort u = c.unicode(); | - |
67 | return (u >= 'a' && u <= 'z') executed: return (u >= 'a' && u <= 'z') || (u >= 'A' && u <= 'Z') || (u >= '0' && u <= '9') || (u == '_') || (u == '-'); Execution Count:16055 | 16055 |
68 | || (u >= 'A' && u <= 'Z') executed: return (u >= 'a' && u <= 'z') || (u >= 'A' && u <= 'Z') || (u >= '0' && u <= '9') || (u == '_') || (u == '-'); Execution Count:16055 | 16055 |
69 | || (u >= '0' && u <= '9') executed: return (u >= 'a' && u <= 'z') || (u >= 'A' && u <= 'Z') || (u >= '0' && u <= '9') || (u == '_') || (u == '-'); Execution Count:16055 | 16055 |
70 | || (u == '_') || (u == '-'); executed: return (u >= 'a' && u <= 'z') || (u >= 'A' && u <= 'Z') || (u >= '0' && u <= '9') || (u == '_') || (u == '-'); Execution Count:16055 | 16055 |
71 | } | - |
72 | | - |
73 | static inline bool isValidNumber(QChar c) | - |
74 | { | - |
75 | register ushort u = c.unicode(); executed (the execution status of this line is deduced): register ushort u = c.unicode(); | - |
76 | return (u >= '0' && u <= '9'); executed: return (u >= '0' && u <= '9'); Execution Count:10184 | 10184 |
77 | } | - |
78 | | - |
79 | #ifndef QT_BOOTSTRAPPED | - |
80 | static bool argToString(const QDBusArgument &arg, QString &out); | - |
81 | | - |
82 | static bool variantToString(const QVariant &arg, QString &out) | - |
83 | { | - |
84 | int argType = arg.userType(); never executed (the execution status of this line is deduced): int argType = arg.userType(); | - |
85 | | - |
86 | if (argType == QVariant::StringList) { never evaluated: argType == QVariant::StringList | 0 |
87 | out += QLatin1Char('{'); never executed (the execution status of this line is deduced): out += QLatin1Char('{'); | - |
88 | QStringList list = arg.toStringList(); never executed (the execution status of this line is deduced): QStringList list = arg.toStringList(); | - |
89 | foreach (const QString &item, list) never executed (the execution status of this line is deduced): for (QForeachContainer<__typeof__(list)> _container_(list); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QString &item = *_container_.i;; __extension__ ({--_container_.brk; break;})) | - |
90 | out += QLatin1Char('\"') + item + QLatin1String("\", "); never executed: out += QLatin1Char('\"') + item + QLatin1String("\", "); | 0 |
91 | if (!list.isEmpty()) never evaluated: !list.isEmpty() | 0 |
92 | out.chop(2); never executed: out.chop(2); | 0 |
93 | out += QLatin1Char('}'); never executed (the execution status of this line is deduced): out += QLatin1Char('}'); | - |
94 | } else if (argType == QVariant::ByteArray) { never executed: } never evaluated: argType == QVariant::ByteArray | 0 |
95 | out += QLatin1Char('{'); never executed (the execution status of this line is deduced): out += QLatin1Char('{'); | - |
96 | QByteArray list = arg.toByteArray(); never executed (the execution status of this line is deduced): QByteArray list = arg.toByteArray(); | - |
97 | for (int i = 0; i < list.count(); ++i) { never evaluated: i < list.count() | 0 |
98 | out += QString::number(list.at(i)); never executed (the execution status of this line is deduced): out += QString::number(list.at(i)); | - |
99 | out += QLatin1String(", "); never executed (the execution status of this line is deduced): out += QLatin1String(", "); | - |
100 | } | 0 |
101 | if (!list.isEmpty()) never evaluated: !list.isEmpty() | 0 |
102 | out.chop(2); never executed: out.chop(2); | 0 |
103 | out += QLatin1Char('}'); never executed (the execution status of this line is deduced): out += QLatin1Char('}'); | - |
104 | } else if (argType == QVariant::List) { never executed: } never evaluated: argType == QVariant::List | 0 |
105 | out += QLatin1Char('{'); never executed (the execution status of this line is deduced): out += QLatin1Char('{'); | - |
106 | QList<QVariant> list = arg.toList(); never executed (the execution status of this line is deduced): QList<QVariant> list = arg.toList(); | - |
107 | foreach (const QVariant &item, list) { never executed (the execution status of this line is deduced): for (QForeachContainer<__typeof__(list)> _container_(list); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QVariant &item = *_container_.i;; __extension__ ({--_container_.brk; break;})) { | - |
108 | if (!variantToString(item, out)) never evaluated: !variantToString(item, out) | 0 |
109 | return false; never executed: return false; | 0 |
110 | out += QLatin1String(", "); never executed (the execution status of this line is deduced): out += QLatin1String(", "); | - |
111 | } | 0 |
112 | if (!list.isEmpty()) never evaluated: !list.isEmpty() | 0 |
113 | out.chop(2); never executed: out.chop(2); | 0 |
114 | out += QLatin1Char('}'); never executed (the execution status of this line is deduced): out += QLatin1Char('}'); | - |
115 | } else if (argType == QMetaType::Char || argType == QMetaType::Short || argType == QMetaType::Int never executed: } never evaluated: argType == QMetaType::Char never evaluated: argType == QMetaType::Short never evaluated: argType == QMetaType::Int | 0 |
116 | || argType == QMetaType::Long || argType == QMetaType::LongLong) { never evaluated: argType == QMetaType::Long never evaluated: argType == QMetaType::LongLong | 0 |
117 | out += QString::number(arg.toLongLong()); never executed (the execution status of this line is deduced): out += QString::number(arg.toLongLong()); | - |
118 | } else if (argType == QMetaType::UChar || argType == QMetaType::UShort || argType == QMetaType::UInt never executed: } never evaluated: argType == QMetaType::UChar never evaluated: argType == QMetaType::UShort never evaluated: argType == QMetaType::UInt | 0 |
119 | || argType == QMetaType::ULong || argType == QMetaType::ULongLong) { never evaluated: argType == QMetaType::ULong never evaluated: argType == QMetaType::ULongLong | 0 |
120 | out += QString::number(arg.toULongLong()); never executed (the execution status of this line is deduced): out += QString::number(arg.toULongLong()); | - |
121 | } else if (argType == QMetaType::Double) { never executed: } never evaluated: argType == QMetaType::Double | 0 |
122 | out += QString::number(arg.toDouble()); never executed (the execution status of this line is deduced): out += QString::number(arg.toDouble()); | - |
123 | } else if (argType == QMetaType::Bool) { never executed: } never evaluated: argType == QMetaType::Bool | 0 |
124 | out += QLatin1String(arg.toBool() ? "true" : "false"); never executed (the execution status of this line is deduced): out += QLatin1String(arg.toBool() ? "true" : "false"); | - |
125 | } else if (argType == qMetaTypeId<QDBusArgument>()) { never executed: } never evaluated: argType == qMetaTypeId<QDBusArgument>() | 0 |
126 | argToString(qvariant_cast<QDBusArgument>(arg), out); never executed (the execution status of this line is deduced): argToString(qvariant_cast<QDBusArgument>(arg), out); | - |
127 | } else if (argType == qMetaTypeId<QDBusObjectPath>()) { never executed: } never evaluated: argType == qMetaTypeId<QDBusObjectPath>() | 0 |
128 | const QString path = qvariant_cast<QDBusObjectPath>(arg).path(); never executed (the execution status of this line is deduced): const QString path = qvariant_cast<QDBusObjectPath>(arg).path(); | - |
129 | out += QLatin1String("[ObjectPath: "); never executed (the execution status of this line is deduced): out += QLatin1String("[ObjectPath: "); | - |
130 | out += path; never executed (the execution status of this line is deduced): out += path; | - |
131 | out += QLatin1Char(']'); never executed (the execution status of this line is deduced): out += QLatin1Char(']'); | - |
132 | } else if (argType == qMetaTypeId<QDBusSignature>()) { never executed: } never evaluated: argType == qMetaTypeId<QDBusSignature>() | 0 |
133 | out += QLatin1String("[Signature: ") + qvariant_cast<QDBusSignature>(arg).signature(); never executed (the execution status of this line is deduced): out += QLatin1String("[Signature: ") + qvariant_cast<QDBusSignature>(arg).signature(); | - |
134 | out += QLatin1Char(']'); never executed (the execution status of this line is deduced): out += QLatin1Char(']'); | - |
135 | } else if (argType == qMetaTypeId<QDBusUnixFileDescriptor>()) { never executed: } never evaluated: argType == qMetaTypeId<QDBusUnixFileDescriptor>() | 0 |
136 | out += QLatin1String("[Unix FD: "); never executed (the execution status of this line is deduced): out += QLatin1String("[Unix FD: "); | - |
137 | out += QLatin1String(qvariant_cast<QDBusUnixFileDescriptor>(arg).isValid() ? "valid" : "not valid"); never executed (the execution status of this line is deduced): out += QLatin1String(qvariant_cast<QDBusUnixFileDescriptor>(arg).isValid() ? "valid" : "not valid"); | - |
138 | out += QLatin1Char(']'); never executed (the execution status of this line is deduced): out += QLatin1Char(']'); | - |
139 | } else if (argType == qMetaTypeId<QDBusVariant>()) { never executed: } never evaluated: argType == qMetaTypeId<QDBusVariant>() | 0 |
140 | const QVariant v = qvariant_cast<QDBusVariant>(arg).variant(); never executed (the execution status of this line is deduced): const QVariant v = qvariant_cast<QDBusVariant>(arg).variant(); | - |
141 | out += QLatin1String("[Variant"); never executed (the execution status of this line is deduced): out += QLatin1String("[Variant"); | - |
142 | int vUserType = v.userType(); never executed (the execution status of this line is deduced): int vUserType = v.userType(); | - |
143 | if (vUserType != qMetaTypeId<QDBusVariant>() never evaluated: vUserType != qMetaTypeId<QDBusVariant>() | 0 |
144 | && vUserType != qMetaTypeId<QDBusSignature>() never evaluated: vUserType != qMetaTypeId<QDBusSignature>() | 0 |
145 | && vUserType != qMetaTypeId<QDBusObjectPath>() never evaluated: vUserType != qMetaTypeId<QDBusObjectPath>() | 0 |
146 | && vUserType != qMetaTypeId<QDBusArgument>()) never evaluated: vUserType != qMetaTypeId<QDBusArgument>() | 0 |
147 | out += QLatin1Char('(') + QLatin1String(v.typeName()) + QLatin1Char(')'); never executed: out += QLatin1Char('(') + QLatin1String(v.typeName()) + QLatin1Char(')'); | 0 |
148 | out += QLatin1String(": "); never executed (the execution status of this line is deduced): out += QLatin1String(": "); | - |
149 | if (!variantToString(v, out)) never evaluated: !variantToString(v, out) | 0 |
150 | return false; never executed: return false; | 0 |
151 | out += QLatin1Char(']'); never executed (the execution status of this line is deduced): out += QLatin1Char(']'); | - |
152 | } else if (arg.canConvert(QVariant::String)) { never executed: } never evaluated: arg.canConvert(QVariant::String) | 0 |
153 | out += QLatin1Char('\"') + arg.toString() + QLatin1Char('\"'); never executed (the execution status of this line is deduced): out += QLatin1Char('\"') + arg.toString() + QLatin1Char('\"'); | - |
154 | } else { | 0 |
155 | out += QLatin1Char('['); never executed (the execution status of this line is deduced): out += QLatin1Char('['); | - |
156 | out += QLatin1String(arg.typeName()); never executed (the execution status of this line is deduced): out += QLatin1String(arg.typeName()); | - |
157 | out += QLatin1Char(']'); never executed (the execution status of this line is deduced): out += QLatin1Char(']'); | - |
158 | } | 0 |
159 | | - |
160 | return true; never executed: return true; | 0 |
161 | } | - |
162 | | - |
163 | bool argToString(const QDBusArgument &busArg, QString &out) | - |
164 | { | - |
165 | QString busSig = busArg.currentSignature(); never executed (the execution status of this line is deduced): QString busSig = busArg.currentSignature(); | - |
166 | bool doIterate = false; never executed (the execution status of this line is deduced): bool doIterate = false; | - |
167 | QDBusArgument::ElementType elementType = busArg.currentType(); never executed (the execution status of this line is deduced): QDBusArgument::ElementType elementType = busArg.currentType(); | - |
168 | | - |
169 | if (elementType != QDBusArgument::BasicType && elementType != QDBusArgument::VariantType never evaluated: elementType != QDBusArgument::BasicType never evaluated: elementType != QDBusArgument::VariantType | 0 |
170 | && elementType != QDBusArgument::MapEntryType) never evaluated: elementType != QDBusArgument::MapEntryType | 0 |
171 | out += QLatin1String("[Argument: ") + busSig + QLatin1Char(' '); never executed: out += QLatin1String("[Argument: ") + busSig + QLatin1Char(' '); | 0 |
172 | | - |
173 | switch (elementType) { | - |
174 | case QDBusArgument::BasicType: | - |
175 | case QDBusArgument::VariantType: | - |
176 | if (!variantToString(busArg.asVariant(), out)) never evaluated: !variantToString(busArg.asVariant(), out) | 0 |
177 | return false; never executed: return false; | 0 |
178 | break; | 0 |
179 | case QDBusArgument::StructureType: | - |
180 | busArg.beginStructure(); never executed (the execution status of this line is deduced): busArg.beginStructure(); | - |
181 | doIterate = true; never executed (the execution status of this line is deduced): doIterate = true; | - |
182 | break; | 0 |
183 | case QDBusArgument::ArrayType: | - |
184 | busArg.beginArray(); never executed (the execution status of this line is deduced): busArg.beginArray(); | - |
185 | out += QLatin1Char('{'); never executed (the execution status of this line is deduced): out += QLatin1Char('{'); | - |
186 | doIterate = true; never executed (the execution status of this line is deduced): doIterate = true; | - |
187 | break; | 0 |
188 | case QDBusArgument::MapType: | - |
189 | busArg.beginMap(); never executed (the execution status of this line is deduced): busArg.beginMap(); | - |
190 | out += QLatin1Char('{'); never executed (the execution status of this line is deduced): out += QLatin1Char('{'); | - |
191 | doIterate = true; never executed (the execution status of this line is deduced): doIterate = true; | - |
192 | break; | 0 |
193 | case QDBusArgument::MapEntryType: | - |
194 | busArg.beginMapEntry(); never executed (the execution status of this line is deduced): busArg.beginMapEntry(); | - |
195 | if (!variantToString(busArg.asVariant(), out)) never evaluated: !variantToString(busArg.asVariant(), out) | 0 |
196 | return false; never executed: return false; | 0 |
197 | out += QLatin1String(" = "); never executed (the execution status of this line is deduced): out += QLatin1String(" = "); | - |
198 | if (!argToString(busArg, out)) never evaluated: !argToString(busArg, out) | 0 |
199 | return false; never executed: return false; | 0 |
200 | busArg.endMapEntry(); never executed (the execution status of this line is deduced): busArg.endMapEntry(); | - |
201 | break; | 0 |
202 | case QDBusArgument::UnknownType: | - |
203 | default: | - |
204 | out += QLatin1String("<ERROR - Unknown Type>"); never executed (the execution status of this line is deduced): out += QLatin1String("<ERROR - Unknown Type>"); | - |
205 | return false; never executed: return false; | 0 |
206 | } | - |
207 | if (doIterate && !busArg.atEnd()) { never evaluated: doIterate never evaluated: !busArg.atEnd() | 0 |
208 | while (!busArg.atEnd()) { never evaluated: !busArg.atEnd() | 0 |
209 | if (!argToString(busArg, out)) never evaluated: !argToString(busArg, out) | 0 |
210 | return false; never executed: return false; | 0 |
211 | out += QLatin1String(", "); never executed (the execution status of this line is deduced): out += QLatin1String(", "); | - |
212 | } | 0 |
213 | out.chop(2); never executed (the execution status of this line is deduced): out.chop(2); | - |
214 | } | 0 |
215 | switch (elementType) { | - |
216 | case QDBusArgument::BasicType: | - |
217 | case QDBusArgument::VariantType: | - |
218 | case QDBusArgument::UnknownType: | - |
219 | case QDBusArgument::MapEntryType: | - |
220 | // nothing to do | - |
221 | break; | 0 |
222 | case QDBusArgument::StructureType: | - |
223 | busArg.endStructure(); never executed (the execution status of this line is deduced): busArg.endStructure(); | - |
224 | break; | 0 |
225 | case QDBusArgument::ArrayType: | - |
226 | out += QLatin1Char('}'); never executed (the execution status of this line is deduced): out += QLatin1Char('}'); | - |
227 | busArg.endArray(); never executed (the execution status of this line is deduced): busArg.endArray(); | - |
228 | break; | 0 |
229 | case QDBusArgument::MapType: | - |
230 | out += QLatin1Char('}'); never executed (the execution status of this line is deduced): out += QLatin1Char('}'); | - |
231 | busArg.endMap(); never executed (the execution status of this line is deduced): busArg.endMap(); | - |
232 | break; | 0 |
233 | } | - |
234 | | - |
235 | if (elementType != QDBusArgument::BasicType && elementType != QDBusArgument::VariantType never evaluated: elementType != QDBusArgument::BasicType never evaluated: elementType != QDBusArgument::VariantType | 0 |
236 | && elementType != QDBusArgument::MapEntryType) never evaluated: elementType != QDBusArgument::MapEntryType | 0 |
237 | out += QLatin1Char(']'); never executed: out += QLatin1Char(']'); | 0 |
238 | | - |
239 | return true; never executed: return true; | 0 |
240 | } | - |
241 | #endif | - |
242 | | - |
243 | //------- D-Bus Types -------- | - |
244 | static const char oneLetterTypes[] = "vsogybnqiuxtdh"; | - |
245 | static const char basicTypes[] = "sogybnqiuxtdh"; | - |
246 | static const char fixedTypes[] = "ybnqiuxtdh"; | - |
247 | | - |
248 | static bool isBasicType(int c) | - |
249 | { | - |
250 | return c != DBUS_TYPE_INVALID && strchr(basicTypes, c) != NULL; executed: return c != ((int) '\0') && strchr(basicTypes, c) != __null; Execution Count:336 | 336 |
251 | } | - |
252 | | - |
253 | static bool isFixedType(int c) | - |
254 | { | - |
255 | return c != DBUS_TYPE_INVALID && strchr(fixedTypes, c) != NULL; executed: return c != ((int) '\0') && strchr(fixedTypes, c) != __null; Execution Count:31 | 31 |
256 | } | - |
257 | | - |
258 | // Returns a pointer to one-past-end of this type if it's valid; | - |
259 | // returns NULL if it isn't valid. | - |
260 | static const char *validateSingleType(const char *signature) | - |
261 | { | - |
262 | register char c = *signature; executed (the execution status of this line is deduced): register char c = *signature; | - |
263 | if (c == DBUS_TYPE_INVALID) evaluated: c == ((int) '\0') yes Evaluation Count:29 | yes Evaluation Count:3830 |
| 29-3830 |
264 | return 0; executed: return 0; Execution Count:29 | 29 |
265 | | - |
266 | // is it one of the one-letter types? | - |
267 | if (strchr(oneLetterTypes, c) != NULL) evaluated: strchr(oneLetterTypes, c) != __null yes Evaluation Count:2781 | yes Evaluation Count:1049 |
| 1049-2781 |
268 | return signature + 1; executed: return signature + 1; Execution Count:2781 | 2781 |
269 | | - |
270 | // is it an array? | - |
271 | if (c == DBUS_TYPE_ARRAY) { evaluated: c == ((int) 'a') yes Evaluation Count:655 | yes Evaluation Count:394 |
| 394-655 |
272 | // then it's valid if the next type is valid | - |
273 | // or if it's a dict-entry | - |
274 | c = *++signature; executed (the execution status of this line is deduced): c = *++signature; | - |
275 | if (c == DBUS_DICT_ENTRY_BEGIN_CHAR) { evaluated: c == ((int) '{') yes Evaluation Count:280 | yes Evaluation Count:375 |
| 280-375 |
276 | // beginning of a dictionary entry | - |
277 | // a dictionary entry has a key which is of basic types | - |
278 | // and a free value | - |
279 | c = *++signature; executed (the execution status of this line is deduced): c = *++signature; | - |
280 | if (!isBasicType(c)) evaluated: !isBasicType(c) yes Evaluation Count:16 | yes Evaluation Count:264 |
| 16-264 |
281 | return 0; executed: return 0; Execution Count:16 | 16 |
282 | signature = validateSingleType(signature + 1); executed (the execution status of this line is deduced): signature = validateSingleType(signature + 1); | - |
283 | return signature && *signature == DBUS_DICT_ENTRY_END_CHAR ? signature + 1 : 0; executed: return signature && *signature == ((int) '}') ? signature + 1 : 0; Execution Count:264 | 264 |
284 | } | - |
285 | | - |
286 | return validateSingleType(signature); executed: return validateSingleType(signature); Execution Count:375 | 375 |
287 | } | - |
288 | | - |
289 | if (c == DBUS_STRUCT_BEGIN_CHAR) { evaluated: c == ((int) '(') yes Evaluation Count:354 | yes Evaluation Count:40 |
| 40-354 |
290 | // beginning of a struct | - |
291 | ++signature; executed (the execution status of this line is deduced): ++signature; | - |
292 | while (true) { partially evaluated: true yes Evaluation Count:819 | no Evaluation Count:0 |
| 0-819 |
293 | signature = validateSingleType(signature); executed (the execution status of this line is deduced): signature = validateSingleType(signature); | - |
294 | if (!signature) evaluated: !signature yes Evaluation Count:34 | yes Evaluation Count:785 |
| 34-785 |
295 | return 0; executed: return 0; Execution Count:34 | 34 |
296 | if (*signature == DBUS_STRUCT_END_CHAR) evaluated: *signature == ((int) ')') yes Evaluation Count:320 | yes Evaluation Count:465 |
| 320-465 |
297 | return signature + 1; executed: return signature + 1; Execution Count:320 | 320 |
298 | } executed: } Execution Count:465 | 465 |
299 | } | 0 |
300 | | - |
301 | // invalid/unknown type | - |
302 | return 0; executed: return 0; Execution Count:40 | 40 |
303 | } | - |
304 | | - |
305 | /*! | - |
306 | \namespace QDBusUtil | - |
307 | \inmodule QtDBus | - |
308 | \internal | - |
309 | | - |
310 | \brief The QDBusUtil namespace contains a few functions that are of general use when | - |
311 | dealing with D-Bus strings. | - |
312 | */ | - |
313 | namespace QDBusUtil | - |
314 | { | - |
315 | /*! | - |
316 | \internal | - |
317 | \since 4.5 | - |
318 | Dumps the contents of a Qt D-Bus argument from \a arg into a string. | - |
319 | */ | - |
320 | QString argumentToString(const QVariant &arg) | - |
321 | { | - |
322 | QString out; never executed (the execution status of this line is deduced): QString out; | - |
323 | | - |
324 | #ifndef QT_BOOTSTRAPPED | - |
325 | variantToString(arg, out); never executed (the execution status of this line is deduced): variantToString(arg, out); | - |
326 | #else | - |
327 | Q_UNUSED(arg); | - |
328 | #endif | - |
329 | | - |
330 | return out; never executed: return out; | 0 |
331 | } | - |
332 | | - |
333 | /*! | - |
334 | \internal | - |
335 | \fn bool QDBusUtil::isValidPartOfObjectPath(const QString &part) | - |
336 | See QDBusUtil::isValidObjectPath | - |
337 | */ | - |
338 | bool isValidPartOfObjectPath(const QString &part) | - |
339 | { | - |
340 | if (part.isEmpty()) partially evaluated: part.isEmpty() no Evaluation Count:0 | yes Evaluation Count:1895 |
| 0-1895 |
341 | return false; // can't be valid if it's empty never executed: return false; | 0 |
342 | | - |
343 | const QChar *c = part.unicode(); executed (the execution status of this line is deduced): const QChar *c = part.unicode(); | - |
344 | for (int i = 0; i < part.length(); ++i) evaluated: i < part.length() yes Evaluation Count:10708 | yes Evaluation Count:1895 |
| 1895-10708 |
345 | if (!isValidCharacterNoDash(c[i])) partially evaluated: !isValidCharacterNoDash(c[i]) no Evaluation Count:0 | yes Evaluation Count:10708 |
| 0-10708 |
346 | return false; never executed: return false; | 0 |
347 | | - |
348 | return true; executed: return true; Execution Count:1895 | 1895 |
349 | } | - |
350 | | - |
351 | /*! | - |
352 | \fn bool QDBusUtil::isValidInterfaceName(const QString &ifaceName) | - |
353 | Returns true if this is \a ifaceName is a valid interface name. | - |
354 | | - |
355 | Valid interface names must: | - |
356 | \list | - |
357 | \li not be empty | - |
358 | \li not exceed 255 characters in length | - |
359 | \li be composed of dot-separated string components that contain only ASCII letters, digits | - |
360 | and the underscore ("_") character | - |
361 | \li contain at least two such components | - |
362 | \endlist | - |
363 | */ | - |
364 | bool isValidInterfaceName(const QString& ifaceName) | - |
365 | { | - |
366 | if (ifaceName.isEmpty() || ifaceName.length() > DBUS_MAXIMUM_NAME_LENGTH) partially evaluated: ifaceName.isEmpty() no Evaluation Count:0 | yes Evaluation Count:1628 |
partially evaluated: ifaceName.length() > 255 no Evaluation Count:0 | yes Evaluation Count:1628 |
| 0-1628 |
367 | return false; never executed: return false; | 0 |
368 | | - |
369 | QStringList parts = ifaceName.split(QLatin1Char('.')); executed (the execution status of this line is deduced): QStringList parts = ifaceName.split(QLatin1Char('.')); | - |
370 | if (parts.count() < 2) partially evaluated: parts.count() < 2 no Evaluation Count:0 | yes Evaluation Count:1628 |
| 0-1628 |
371 | return false; // at least two parts never executed: return false; | 0 |
372 | | - |
373 | for (int i = 0; i < parts.count(); ++i) evaluated: i < parts.count() yes Evaluation Count:5741 | yes Evaluation Count:1628 |
| 1628-5741 |
374 | if (!isValidMemberName(parts.at(i))) partially evaluated: !isValidMemberName(parts.at(i)) no Evaluation Count:0 | yes Evaluation Count:5741 |
| 0-5741 |
375 | return false; never executed: return false; | 0 |
376 | | - |
377 | return true; executed: return true; Execution Count:1628 | 1628 |
378 | } | - |
379 | | - |
380 | /*! | - |
381 | \fn bool QDBusUtil::isValidUniqueConnectionName(const QString &connName) | - |
382 | Returns true if \a connName is a valid unique connection name. | - |
383 | | - |
384 | Unique connection names start with a colon (":") and are followed by a list of dot-separated | - |
385 | components composed of ASCII letters, digits, the hyphen or the underscore ("_") character. | - |
386 | */ | - |
387 | bool isValidUniqueConnectionName(const QString &connName) | - |
388 | { | - |
389 | if (connName.isEmpty() || connName.length() > DBUS_MAXIMUM_NAME_LENGTH || partially evaluated: connName.isEmpty() no Evaluation Count:0 | yes Evaluation Count:347 |
partially evaluated: connName.length() > 255 no Evaluation Count:0 | yes Evaluation Count:347 |
| 0-347 |
390 | !connName.startsWith(QLatin1Char(':'))) evaluated: !connName.startsWith(QLatin1Char(':')) yes Evaluation Count:30 | yes Evaluation Count:317 |
| 30-317 |
391 | return false; executed: return false; Execution Count:30 | 30 |
392 | | - |
393 | QStringList parts = connName.mid(1).split(QLatin1Char('.')); executed (the execution status of this line is deduced): QStringList parts = connName.mid(1).split(QLatin1Char('.')); | - |
394 | if (parts.count() < 1) partially evaluated: parts.count() < 1 no Evaluation Count:0 | yes Evaluation Count:317 |
| 0-317 |
395 | return false; never executed: return false; | 0 |
396 | | - |
397 | for (int i = 0; i < parts.count(); ++i) { evaluated: i < parts.count() yes Evaluation Count:634 | yes Evaluation Count:317 |
| 317-634 |
398 | const QString &part = parts.at(i); executed (the execution status of this line is deduced): const QString &part = parts.at(i); | - |
399 | if (part.isEmpty()) partially evaluated: part.isEmpty() no Evaluation Count:0 | yes Evaluation Count:634 |
| 0-634 |
400 | return false; never executed: return false; | 0 |
401 | | - |
402 | const QChar* c = part.unicode(); executed (the execution status of this line is deduced): const QChar* c = part.unicode(); | - |
403 | for (int j = 0; j < part.length(); ++j) evaluated: j < part.length() yes Evaluation Count:1585 | yes Evaluation Count:634 |
| 634-1585 |
404 | if (!isValidCharacter(c[j])) partially evaluated: !isValidCharacter(c[j]) no Evaluation Count:0 | yes Evaluation Count:1585 |
| 0-1585 |
405 | return false; never executed: return false; | 0 |
406 | } executed: } Execution Count:634 | 634 |
407 | | - |
408 | return true; executed: return true; Execution Count:317 | 317 |
409 | } | - |
410 | | - |
411 | /*! | - |
412 | \fn bool QDBusUtil::isValidBusName(const QString &busName) | - |
413 | Returns true if \a busName is a valid bus name. | - |
414 | | - |
415 | A valid bus name is either a valid unique connection name or follows the rules: | - |
416 | \list | - |
417 | \li is not empty | - |
418 | \li does not exceed 255 characters in length | - |
419 | \li be composed of dot-separated string components that contain only ASCII letters, digits, | - |
420 | hyphens or underscores ("_"), but don't start with a digit | - |
421 | \li contains at least two such elements | - |
422 | \endlist | - |
423 | | - |
424 | \sa isValidUniqueConnectionName() | - |
425 | */ | - |
426 | bool isValidBusName(const QString &busName) | - |
427 | { | - |
428 | if (busName.isEmpty() || busName.length() > DBUS_MAXIMUM_NAME_LENGTH) partially evaluated: busName.isEmpty() no Evaluation Count:0 | yes Evaluation Count:746 |
partially evaluated: busName.length() > 255 no Evaluation Count:0 | yes Evaluation Count:746 |
| 0-746 |
429 | return false; never executed: return false; | 0 |
430 | | - |
431 | if (busName.startsWith(QLatin1Char(':'))) evaluated: busName.startsWith(QLatin1Char(':')) yes Evaluation Count:208 | yes Evaluation Count:538 |
| 208-538 |
432 | return isValidUniqueConnectionName(busName); executed: return isValidUniqueConnectionName(busName); Execution Count:208 | 208 |
433 | | - |
434 | QStringList parts = busName.split(QLatin1Char('.')); executed (the execution status of this line is deduced): QStringList parts = busName.split(QLatin1Char('.')); | - |
435 | if (parts.count() < 1) partially evaluated: parts.count() < 1 no Evaluation Count:0 | yes Evaluation Count:538 |
| 0-538 |
436 | return false; never executed: return false; | 0 |
437 | | - |
438 | for (int i = 0; i < parts.count(); ++i) { evaluated: i < parts.count() yes Evaluation Count:2043 | yes Evaluation Count:531 |
| 531-2043 |
439 | const QString &part = parts.at(i); executed (the execution status of this line is deduced): const QString &part = parts.at(i); | - |
440 | if (part.isEmpty()) partially evaluated: part.isEmpty() no Evaluation Count:0 | yes Evaluation Count:2043 |
| 0-2043 |
441 | return false; never executed: return false; | 0 |
442 | | - |
443 | const QChar *c = part.unicode(); executed (the execution status of this line is deduced): const QChar *c = part.unicode(); | - |
444 | if (isValidNumber(c[0])) partially evaluated: isValidNumber(c[0]) no Evaluation Count:0 | yes Evaluation Count:2043 |
| 0-2043 |
445 | return false; never executed: return false; | 0 |
446 | for (int j = 0; j < part.length(); ++j) evaluated: j < part.length() yes Evaluation Count:14470 | yes Evaluation Count:2036 |
| 2036-14470 |
447 | if (!isValidCharacter(c[j])) evaluated: !isValidCharacter(c[j]) yes Evaluation Count:7 | yes Evaluation Count:14463 |
| 7-14463 |
448 | return false; executed: return false; Execution Count:7 | 7 |
449 | } executed: } Execution Count:2036 | 2036 |
450 | | - |
451 | return true; executed: return true; Execution Count:531 | 531 |
452 | } | - |
453 | | - |
454 | /*! | - |
455 | \fn bool QDBusUtil::isValidMemberName(const QString &memberName) | - |
456 | Returns true if \a memberName is a valid member name. A valid member name does not exceed | - |
457 | 255 characters in length, is not empty, is composed only of ASCII letters, digits and | - |
458 | underscores, but does not start with a digit. | - |
459 | */ | - |
460 | bool isValidMemberName(const QString &memberName) | - |
461 | { | - |
462 | if (memberName.isEmpty() || memberName.length() > DBUS_MAXIMUM_NAME_LENGTH) partially evaluated: memberName.isEmpty() no Evaluation Count:0 | yes Evaluation Count:8141 |
partially evaluated: memberName.length() > 255 no Evaluation Count:0 | yes Evaluation Count:8141 |
| 0-8141 |
463 | return false; never executed: return false; | 0 |
464 | | - |
465 | const QChar* c = memberName.unicode(); executed (the execution status of this line is deduced): const QChar* c = memberName.unicode(); | - |
466 | if (isValidNumber(c[0])) partially evaluated: isValidNumber(c[0]) no Evaluation Count:0 | yes Evaluation Count:8141 |
| 0-8141 |
467 | return false; never executed: return false; | 0 |
468 | for (int j = 0; j < memberName.length(); ++j) evaluated: j < memberName.length() yes Evaluation Count:62656 | yes Evaluation Count:8141 |
| 8141-62656 |
469 | if (!isValidCharacterNoDash(c[j])) partially evaluated: !isValidCharacterNoDash(c[j]) no Evaluation Count:0 | yes Evaluation Count:62656 |
| 0-62656 |
470 | return false; never executed: return false; | 0 |
471 | return true; executed: return true; Execution Count:8141 | 8141 |
472 | } | - |
473 | | - |
474 | /*! | - |
475 | \fn bool QDBusUtil::isValidErrorName(const QString &errorName) | - |
476 | Returns true if \a errorName is a valid error name. Valid error names are valid interface | - |
477 | names and vice-versa, so this function is actually an alias for isValidInterfaceName. | - |
478 | */ | - |
479 | bool isValidErrorName(const QString &errorName) | - |
480 | { | - |
481 | return isValidInterfaceName(errorName); never executed: return isValidInterfaceName(errorName); | 0 |
482 | } | - |
483 | | - |
484 | /*! | - |
485 | \fn bool QDBusUtil::isValidObjectPath(const QString &path) | - |
486 | Returns true if \a path is valid object path. | - |
487 | | - |
488 | Valid object paths follow the rules: | - |
489 | \list | - |
490 | \li start with the slash character ("/") | - |
491 | \li do not end in a slash, unless the path is just the initial slash | - |
492 | \li do not contain any two slashes in sequence | - |
493 | \li contain slash-separated parts, each of which is composed of ASCII letters, digits and | - |
494 | underscores ("_") | - |
495 | \endlist | - |
496 | */ | - |
497 | bool isValidObjectPath(const QString &path) | - |
498 | { | - |
499 | if (path == QLatin1String("/")) evaluated: path == QLatin1String("/") yes Evaluation Count:613 | yes Evaluation Count:782 |
| 613-782 |
500 | return true; executed: return true; Execution Count:613 | 613 |
501 | | - |
502 | if (!path.startsWith(QLatin1Char('/')) || path.indexOf(QLatin1String("//")) != -1 || evaluated: !path.startsWith(QLatin1Char('/')) yes Evaluation Count:14 | yes Evaluation Count:768 |
partially evaluated: path.indexOf(QLatin1String("//")) != -1 no Evaluation Count:0 | yes Evaluation Count:768 |
| 0-768 |
503 | path.endsWith(QLatin1Char('/'))) partially evaluated: path.endsWith(QLatin1Char('/')) no Evaluation Count:0 | yes Evaluation Count:768 |
| 0-768 |
504 | return false; executed: return false; Execution Count:14 | 14 |
505 | | - |
506 | QStringList parts = path.split(QLatin1Char('/')); executed (the execution status of this line is deduced): QStringList parts = path.split(QLatin1Char('/')); | - |
507 | Q_ASSERT(parts.count() >= 1); executed (the execution status of this line is deduced): qt_noop(); | - |
508 | parts.removeFirst(); // it starts with /, so we get an empty first part executed (the execution status of this line is deduced): parts.removeFirst(); | - |
509 | | - |
510 | for (int i = 0; i < parts.count(); ++i) evaluated: i < parts.count() yes Evaluation Count:1895 | yes Evaluation Count:768 |
| 768-1895 |
511 | if (!isValidPartOfObjectPath(parts.at(i))) partially evaluated: !isValidPartOfObjectPath(parts.at(i)) no Evaluation Count:0 | yes Evaluation Count:1895 |
| 0-1895 |
512 | return false; never executed: return false; | 0 |
513 | | - |
514 | return true; executed: return true; Execution Count:768 | 768 |
515 | } | - |
516 | | - |
517 | /*! | - |
518 | \fn bool QDBusUtil::isValidBasicType(int type) | - |
519 | Returns true if \a c is a valid, basic D-Bus type. | - |
520 | */ | - |
521 | bool isValidBasicType(int c) | - |
522 | { | - |
523 | return isBasicType(c); executed: return isBasicType(c); Execution Count:56 | 56 |
524 | } | - |
525 | | - |
526 | /*! | - |
527 | \fn bool QDBusUtil::isValidFixedType(int type) | - |
528 | Returns true if \a c is a valid, fixed D-Bus type. | - |
529 | */ | - |
530 | bool isValidFixedType(int c) | - |
531 | { | - |
532 | return isFixedType(c); executed: return isFixedType(c); Execution Count:31 | 31 |
533 | } | - |
534 | | - |
535 | | - |
536 | /*! | - |
537 | \fn bool QDBusUtil::isValidSignature(const QString &signature) | - |
538 | Returns true if \a signature is a valid D-Bus type signature for one or more types. | - |
539 | This function returns true if it can all of \a signature into valid, individual types and no | - |
540 | characters remain in \a signature. | - |
541 | | - |
542 | \sa isValidSingleSignature() | - |
543 | */ | - |
544 | bool isValidSignature(const QString &signature) | - |
545 | { | - |
546 | QByteArray ba = signature.toLatin1(); executed (the execution status of this line is deduced): QByteArray ba = signature.toLatin1(); | - |
547 | const char *data = ba.constData(); executed (the execution status of this line is deduced): const char *data = ba.constData(); | - |
548 | while (true) { partially evaluated: true yes Evaluation Count:96 | no Evaluation Count:0 |
| 0-96 |
549 | data = validateSingleType(data); executed (the execution status of this line is deduced): data = validateSingleType(data); | - |
550 | if (!data) evaluated: !data yes Evaluation Count:22 | yes Evaluation Count:74 |
| 22-74 |
551 | return false; executed: return false; Execution Count:22 | 22 |
552 | if (*data == '\0') evaluated: *data == '\0' yes Evaluation Count:40 | yes Evaluation Count:34 |
| 34-40 |
553 | return true; executed: return true; Execution Count:40 | 40 |
554 | } executed: } Execution Count:34 | 34 |
555 | } | 0 |
556 | | - |
557 | /*! | - |
558 | \fn bool QDBusUtil::isValidSingleSignature(const QString &signature) | - |
559 | Returns true if \a signature is a valid D-Bus type signature for exactly one full type. This | - |
560 | function tries to convert the type signature into a D-Bus type and, if it succeeds and no | - |
561 | characters remain in the signature, it returns true. | - |
562 | */ | - |
563 | bool isValidSingleSignature(const QString &signature) | - |
564 | { | - |
565 | QByteArray ba = signature.toLatin1(); executed (the execution status of this line is deduced): QByteArray ba = signature.toLatin1(); | - |
566 | const char *data = validateSingleType(ba.constData()); executed (the execution status of this line is deduced): const char *data = validateSingleType(ba.constData()); | - |
567 | return data && *data == '\0'; executed: return data && *data == '\0'; Execution Count:2305 | 2305 |
568 | } | - |
569 | | - |
570 | } // namespace QDBusUtil | - |
571 | | - |
572 | QT_END_NAMESPACE | - |
573 | | - |
574 | #endif // QT_NO_DBUS | - |
575 | | - |
| | |