author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 16 Apr 2010 15:50:13 +0300 | |
changeset 18 | 2f34d5167611 |
parent 0 | 1918ee327afb |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtDBus module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
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 |
QT_BEGIN_HEADER |
|
63 |
||
64 |
QT_BEGIN_NAMESPACE |
|
65 |
||
66 |
namespace QDBusUtil |
|
67 |
{ |
|
68 |
QDBUS_EXPORT bool isValidInterfaceName(const QString &ifaceName); |
|
69 |
||
70 |
QDBUS_EXPORT bool isValidUniqueConnectionName(const QString &busName); |
|
71 |
||
72 |
QDBUS_EXPORT bool isValidBusName(const QString &busName); |
|
73 |
||
74 |
QDBUS_EXPORT bool isValidMemberName(const QString &memberName); |
|
75 |
||
76 |
QDBUS_EXPORT bool isValidErrorName(const QString &errorName); |
|
77 |
||
78 |
QDBUS_EXPORT bool isValidPartOfObjectPath(const QString &path); |
|
79 |
||
80 |
QDBUS_EXPORT bool isValidObjectPath(const QString &path); |
|
81 |
||
82 |
QDBUS_EXPORT bool isValidSignature(const QString &signature); |
|
83 |
||
84 |
QDBUS_EXPORT bool isValidSingleSignature(const QString &signature); |
|
85 |
||
86 |
QDBUS_EXPORT QString argumentToString(const QVariant &variant); |
|
87 |
||
88 |
enum AllowEmptyFlag { |
|
89 |
EmptyAllowed, |
|
90 |
EmptyNotAllowed |
|
91 |
}; |
|
92 |
||
93 |
inline bool checkInterfaceName(const QString &name, AllowEmptyFlag empty, QDBusError *error) |
|
94 |
{ |
|
95 |
if (name.isEmpty()) { |
|
96 |
if (empty == EmptyAllowed) return true; |
|
97 |
*error = QDBusError(QDBusError::InvalidInterface, QLatin1String("Interface name cannot be empty")); |
|
98 |
return false; |
|
99 |
} |
|
100 |
if (isValidInterfaceName(name)) return true; |
|
101 |
*error = QDBusError(QDBusError::InvalidInterface, QString::fromLatin1("Invalid interface class: %1").arg(name)); |
|
102 |
return false; |
|
103 |
} |
|
104 |
||
105 |
inline bool checkBusName(const QString &name, AllowEmptyFlag empty, QDBusError *error) |
|
106 |
{ |
|
107 |
if (name.isEmpty()) { |
|
108 |
if (empty == EmptyAllowed) return true; |
|
109 |
*error = QDBusError(QDBusError::InvalidService, QLatin1String("Service name cannot be empty")); |
|
110 |
return false; |
|
111 |
} |
|
112 |
if (isValidBusName(name)) return true; |
|
113 |
*error = QDBusError(QDBusError::InvalidService, QString::fromLatin1("Invalid service name: %1").arg(name)); |
|
114 |
return false; |
|
115 |
} |
|
116 |
||
117 |
inline bool checkObjectPath(const QString &path, AllowEmptyFlag empty, QDBusError *error) |
|
118 |
{ |
|
119 |
if (path.isEmpty()) { |
|
120 |
if (empty == EmptyAllowed) return true; |
|
121 |
*error = QDBusError(QDBusError::InvalidObjectPath, QLatin1String("Object path cannot be empty")); |
|
122 |
return false; |
|
123 |
} |
|
124 |
if (isValidObjectPath(path)) return true; |
|
125 |
*error = QDBusError(QDBusError::InvalidObjectPath, QString::fromLatin1("Invalid object path: %1").arg(path)); |
|
126 |
return false; |
|
127 |
} |
|
128 |
||
129 |
inline bool checkMemberName(const QString &name, AllowEmptyFlag empty, QDBusError *error, const char *nameType = 0) |
|
130 |
{ |
|
131 |
if (!nameType) nameType = "member"; |
|
132 |
if (name.isEmpty()) { |
|
133 |
if (empty == EmptyAllowed) return true; |
|
134 |
*error = QDBusError(QDBusError::InvalidMember, QLatin1String(nameType) + QLatin1String(" name cannot be empty")); |
|
135 |
return false; |
|
136 |
} |
|
137 |
if (isValidMemberName(name)) return true; |
|
138 |
*error = QDBusError(QDBusError::InvalidMember, QString::fromLatin1("Invalid %1 name: %2") |
|
139 |
.arg(QString::fromLatin1(nameType), name)); |
|
140 |
return false; |
|
141 |
} |
|
142 |
||
143 |
inline bool checkErrorName(const QString &name, AllowEmptyFlag empty, QDBusError *error) |
|
144 |
{ |
|
145 |
if (name.isEmpty()) { |
|
146 |
if (empty == EmptyAllowed) return true; |
|
147 |
*error = QDBusError(QDBusError::InvalidInterface, QLatin1String("Error name cannot be empty")); |
|
148 |
return false; |
|
149 |
} |
|
150 |
if (isValidErrorName(name)) return true; |
|
151 |
*error = QDBusError(QDBusError::InvalidInterface, QString::fromLatin1("Invalid error name: %1").arg(name)); |
|
152 |
return false; |
|
153 |
} |
|
154 |
} |
|
155 |
||
156 |
QT_END_NAMESPACE |
|
157 |
||
158 |
QT_END_HEADER |
|
159 |
||
160 |
#endif |