1/****************************************************************************
2**
3** Copyright (C) 2014 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//
43// W A R N I N G
44// -------------
45//
46// This file is not part of the Qt API. It exists for the convenience
47// of the QLibrary class. This header file may change from
48// version to version without notice, or even be removed.
49//
50// We mean it.
51//
52
53#ifndef QDBUSUTIL_H
54#define QDBUSUTIL_H
55
56#include <QtCore/qstring.h>
57#include <QtCore/qvariant.h>
58
59#include <QtDBus/qdbusmacros.h>
60#include <QtDBus/qdbuserror.h>
61
62#ifndef QT_NO_DBUS
63
64QT_BEGIN_HEADER
65
66QT_BEGIN_NAMESPACE
67
68namespace QDBusUtil
69{
70 Q_DBUS_EXPORT bool isValidInterfaceName(const QString &ifaceName);
71
72 Q_DBUS_EXPORT bool isValidUniqueConnectionName(const QString &busName);
73
74 Q_DBUS_EXPORT bool isValidBusName(const QString &busName);
75
76 Q_DBUS_EXPORT bool isValidMemberName(const QString &memberName);
77
78 Q_DBUS_EXPORT bool isValidErrorName(const QString &errorName);
79
80 Q_DBUS_EXPORT bool isValidPartOfObjectPath(const QString &path);
81
82 Q_DBUS_EXPORT bool isValidObjectPath(const QString &path);
83
84 Q_DBUS_EXPORT bool isValidFixedType(int c);
85
86 Q_DBUS_EXPORT bool isValidBasicType(int c);
87
88 Q_DBUS_EXPORT bool isValidSignature(const QString &signature);
89
90 Q_DBUS_EXPORT bool isValidSingleSignature(const QString &signature);
91
92 Q_DBUS_EXPORT QString argumentToString(const QVariant &variant);
93
94 enum AllowEmptyFlag {
95 EmptyAllowed,
96 EmptyNotAllowed
97 };
98
99 inline bool checkInterfaceName(const QString &name, AllowEmptyFlag empty, QDBusError *error)
100 {
101 if (name.isEmpty()) {
102 if (empty == EmptyAllowed) return true;
103 *error = QDBusError(QDBusError::InvalidInterface, QLatin1String("Interface name cannot be empty"));
104 return false;
105 }
106 if (isValidInterfaceName(name)) return true;
107 *error = QDBusError(QDBusError::InvalidInterface, QString::fromLatin1("Invalid interface class: %1").arg(name));
108 return false;
109 }
110
111 inline bool checkBusName(const QString &name, AllowEmptyFlag empty, QDBusError *error)
112 {
113 if (name.isEmpty()) {
114 if (empty == EmptyAllowed) return true;
115 *error = QDBusError(QDBusError::InvalidService, QLatin1String("Service name cannot be empty"));
116 return false;
117 }
118 if (isValidBusName(name)) return true;
119 *error = QDBusError(QDBusError::InvalidService, QString::fromLatin1("Invalid service name: %1").arg(name));
120 return false;
121 }
122
123 inline bool checkObjectPath(const QString &path, AllowEmptyFlag empty, QDBusError *error)
124 {
125 if (path.isEmpty()) {
126 if (empty == EmptyAllowed) return true;
127 *error = QDBusError(QDBusError::InvalidObjectPath, QLatin1String("Object path cannot be empty"));
128 return false;
129 }
130 if (isValidObjectPath(path)) return true;
131 *error = QDBusError(QDBusError::InvalidObjectPath, QString::fromLatin1("Invalid object path: %1").arg(path));
132 return false;
133 }
134
135 inline bool checkMemberName(const QString &name, AllowEmptyFlag empty, QDBusError *error, const char *nameType = 0)
136 {
137 if (!nameType) nameType = "member";
138 if (name.isEmpty()) {
139 if (empty == EmptyAllowed) return true;
140 *error = QDBusError(QDBusError::InvalidMember, QLatin1String(nameType) + QLatin1String(" name cannot be empty"));
141 return false;
142 }
143 if (isValidMemberName(name)) return true;
144 *error = QDBusError(QDBusError::InvalidMember, QString::fromLatin1("Invalid %1 name: %2")
145 .arg(QString::fromLatin1(nameType), name));
146 return false;
147 }
148
149 inline bool checkErrorName(const QString &name, AllowEmptyFlag empty, QDBusError *error)
150 {
151 if (name.isEmpty()) {
152 if (empty == EmptyAllowed) return true;
153 *error = QDBusError(QDBusError::InvalidInterface, QLatin1String("Error name cannot be empty"));
154 return false;
155 }
156 if (isValidErrorName(name)) return true;
157 *error = QDBusError(QDBusError::InvalidInterface, QString::fromLatin1("Invalid error name: %1").arg(name));
158 return false;
159 }
160}
161
162QT_END_NAMESPACE
163
164QT_END_HEADER
165
166#endif // QT_NO_DBUS
167#endif
168