source: trunk/src/dbus/qdbusutil_p.h@ 966

Last change on this file since 966 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 5.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtDBus module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
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 isValidSignature(const QString &signature);
85
86 Q_DBUS_EXPORT bool isValidSingleSignature(const QString &signature);
87
88 Q_DBUS_EXPORT QString argumentToString(const QVariant &variant);
89
90 enum AllowEmptyFlag {
91 EmptyAllowed,
92 EmptyNotAllowed
93 };
94
95 inline bool checkInterfaceName(const QString &name, AllowEmptyFlag empty, QDBusError *error)
96 {
97 if (name.isEmpty()) {
98 if (empty == EmptyAllowed) return true;
99 *error = QDBusError(QDBusError::InvalidInterface, QLatin1String("Interface name cannot be empty"));
100 return false;
101 }
102 if (isValidInterfaceName(name)) return true;
103 *error = QDBusError(QDBusError::InvalidInterface, QString::fromLatin1("Invalid interface class: %1").arg(name));
104 return false;
105 }
106
107 inline bool checkBusName(const QString &name, AllowEmptyFlag empty, QDBusError *error)
108 {
109 if (name.isEmpty()) {
110 if (empty == EmptyAllowed) return true;
111 *error = QDBusError(QDBusError::InvalidService, QLatin1String("Service name cannot be empty"));
112 return false;
113 }
114 if (isValidBusName(name)) return true;
115 *error = QDBusError(QDBusError::InvalidService, QString::fromLatin1("Invalid service name: %1").arg(name));
116 return false;
117 }
118
119 inline bool checkObjectPath(const QString &path, AllowEmptyFlag empty, QDBusError *error)
120 {
121 if (path.isEmpty()) {
122 if (empty == EmptyAllowed) return true;
123 *error = QDBusError(QDBusError::InvalidObjectPath, QLatin1String("Object path cannot be empty"));
124 return false;
125 }
126 if (isValidObjectPath(path)) return true;
127 *error = QDBusError(QDBusError::InvalidObjectPath, QString::fromLatin1("Invalid object path: %1").arg(path));
128 return false;
129 }
130
131 inline bool checkMemberName(const QString &name, AllowEmptyFlag empty, QDBusError *error, const char *nameType = 0)
132 {
133 if (!nameType) nameType = "member";
134 if (name.isEmpty()) {
135 if (empty == EmptyAllowed) return true;
136 *error = QDBusError(QDBusError::InvalidMember, QLatin1String(nameType) + QLatin1String(" name cannot be empty"));
137 return false;
138 }
139 if (isValidMemberName(name)) return true;
140 *error = QDBusError(QDBusError::InvalidMember, QString::fromLatin1("Invalid %1 name: %2")
141 .arg(QString::fromLatin1(nameType), name));
142 return false;
143 }
144
145 inline bool checkErrorName(const QString &name, AllowEmptyFlag empty, QDBusError *error)
146 {
147 if (name.isEmpty()) {
148 if (empty == EmptyAllowed) return true;
149 *error = QDBusError(QDBusError::InvalidInterface, QLatin1String("Error name cannot be empty"));
150 return false;
151 }
152 if (isValidErrorName(name)) return true;
153 *error = QDBusError(QDBusError::InvalidInterface, QString::fromLatin1("Invalid error name: %1").arg(name));
154 return false;
155 }
156}
157
158QT_END_NAMESPACE
159
160QT_END_HEADER
161
162#endif // QT_NO_DBUS
163#endif
Note: See TracBrowser for help on using the repository browser.