Qt 4.8
qdbusutil_p.h
Go to the documentation of this file.
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 
65 
67 
68 namespace QDBusUtil
69 {
70  Q_DBUS_EXPORT bool isValidInterfaceName(const QString &ifaceName);
71 
73 
74  Q_DBUS_EXPORT bool isValidBusName(const QString &busName);
75 
77 
78  Q_DBUS_EXPORT bool isValidErrorName(const QString &errorName);
79 
81 
82  Q_DBUS_EXPORT bool isValidObjectPath(const QString &path);
83 
85 
87 
88  Q_DBUS_EXPORT bool isValidSignature(const QString &signature);
89 
90  Q_DBUS_EXPORT bool isValidSingleSignature(const QString &signature);
91 
93 
97  };
98 
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 
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 
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 
163 
165 
166 #endif // QT_NO_DBUS
167 #endif
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
bool isValidObjectPath(const QString &path)
Returns true if path is valid object path.
Definition: qdbusutil.cpp:515
bool checkMemberName(const QString &name, AllowEmptyFlag empty, QDBusError *error, const char *nameType=0)
Definition: qdbusutil_p.h:135
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define error(msg)
The QDBusError class represents an error received from the D-Bus bus or from remote applications foun...
Definition: qdbuserror.h:60
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isValidInterfaceName(const QString &ifaceName)
Returns true if this is ifaceName is a valid interface name.
Definition: qdbusutil.cpp:367
bool checkBusName(const QString &name, AllowEmptyFlag empty, QDBusError *error)
Definition: qdbusutil_p.h:111
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const char * name
bool isValidSignature(const QString &signature)
Returns true if signature is a valid D-Bus type signature for one or more types.
Definition: qdbusutil.cpp:571
bool isValidMemberName(const QString &memberName)
Returns true if memberName is a valid member name.
Definition: qdbusutil.cpp:472
bool isValidSingleSignature(const QString &signature)
Returns true if signature is a valid D-Bus type signature for exactly one full type.
Definition: qdbusutil.cpp:593
bool isValidErrorName(const QString &errorName)
Returns true if errorName is a valid error name.
Definition: qdbusutil.cpp:494
bool isValidFixedType(int c)
Returns true if c is a valid, fixed D-Bus type.
Definition: qdbusutil.cpp:554
bool isValidUniqueConnectionName(const QString &connName)
Returns true if connName is a valid unique connection name.
Definition: qdbusutil.cpp:393
bool isValidBasicType(int c)
Returns true if c is a valid, basic D-Bus type.
Definition: qdbusutil.cpp:542
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
#define Q_DBUS_EXPORT
Definition: qglobal.h:1463
bool checkObjectPath(const QString &path, AllowEmptyFlag empty, QDBusError *error)
Definition: qdbusutil_p.h:123
static QByteArray memberName(const QMetaMethod &member)
bool checkErrorName(const QString &name, AllowEmptyFlag empty, QDBusError *error)
Definition: qdbusutil_p.h:149
bool isValidPartOfObjectPath(const QString &part)
Definition: qdbusutil.cpp:338
const char * variant
The QDBusUtil namespace contains a few functions that are of general use when dealing with D-Bus stri...
bool checkInterfaceName(const QString &name, AllowEmptyFlag empty, QDBusError *error)
Definition: qdbusutil_p.h:99
#define QT_END_HEADER
Definition: qglobal.h:137
QString argumentToString(const QVariant &arg)
Dumps the contents of a QtDBus argument from arg into a string.
Definition: qdbusutil.cpp:324
bool isValidBusName(const QString &busName)
Returns true if busName is a valid bus name.
Definition: qdbusutil.cpp:435