summaryrefslogtreecommitdiffstats
path: root/qt/qdbusutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qt/qdbusutil.cpp')
-rw-r--r--qt/qdbusutil.cpp90
1 files changed, 74 insertions, 16 deletions
diff --git a/qt/qdbusutil.cpp b/qt/qdbusutil.cpp
index e10b3020..d4a86599 100644
--- a/qt/qdbusutil.cpp
+++ b/qt/qdbusutil.cpp
@@ -30,13 +30,22 @@
namespace QDBusUtil
{
-
+ /*!
+ Returns true if this is \p ifaceName is a valid interface name.
+
+ Valid interface names must:
+ - not be empty
+ - not exceed 255 characters in length
+ - be composed of dot-separated string components that contain only ASCII letters, digits and the
+ underscore ("_") character
+ - contain at least two such components
+ */
bool isValidInterfaceName(const QString& ifaceName)
{
if (ifaceName.isEmpty() || ifaceName.length() > DBUS_MAXIMUM_NAME_LENGTH)
return false;
- QStringList parts = ifaceName.split('.');
+ QStringList parts = ifaceName.split(QLatin1Char('.'));
if (parts.count() < 2)
return false; // at least two parts
@@ -47,37 +56,55 @@ namespace QDBusUtil
return true;
}
+ /*!
+ Returns true if \p connName is a valid unique connection name.
+
+ Unique connection names start with a colon (":") and are followed by a list of dot-separated
+ components composed of ASCII letters, digits, the hypen or the underscore ("_") character.
+ */
bool isValidUniqueConnectionName(const QString &connName)
{
if (connName.isEmpty() || connName.length() > DBUS_MAXIMUM_NAME_LENGTH ||
- !connName.startsWith(':'))
+ !connName.startsWith(QLatin1Char(':')))
return false;
- QStringList parts = connName.mid(1).split('.');
+ QStringList parts = connName.mid(1).split(QLatin1Char('.'));
if (parts.count() < 1)
return false;
- QRegExp regex("[a-zA-Z0-9_-]+");
+ QRegExp regex(QLatin1String("[a-zA-Z0-9_-]+"));
foreach (QString part, parts)
if (!regex.exactMatch(part))
return false;
return true;
}
-
+
+ /*!
+ Returns true if \p busName is a valid bus name.
+
+ A valid bus name is either a valid unique connection name or follows the rules:
+ - is not empty
+ - does not exceed 255 characters in length
+ - be composed of dot-separated string components that contain only ASCII letters, digits,
+ hyphens or underscores ("_"), but don't start with a digit
+ - contains at least two such elements
+
+ \see isValidUniqueConnectionName
+ */
bool isValidBusName(const QString &busName)
{
if (busName.isEmpty() || busName.length() > DBUS_MAXIMUM_NAME_LENGTH)
return false;
- if (busName.startsWith(':'))
+ if (busName.startsWith(QLatin1Char(':')))
return isValidUniqueConnectionName(busName);
- QStringList parts = busName.split('.');
+ QStringList parts = busName.split(QLatin1Char('.'));
if (parts.count() < 1)
return false;
- QRegExp regex("[a-zA-Z_-][a-zA-Z0-9_-]*");
+ QRegExp regex(QLatin1String("[a-zA-Z_-][a-zA-Z0-9_-]*"));
foreach (QString part, parts)
if (!regex.exactMatch(part))
return false;
@@ -85,34 +112,53 @@ namespace QDBusUtil
return true;
}
+ /*!
+ Returns true if \p memberName is a valid member name. A valid member name does not exceed
+ 255 characters in length, is not empty, is composed only of ASCII letters, digits and
+ underscores, but does not start with a digit.
+ */
bool isValidMemberName(const QString &memberName)
{
if (memberName.isEmpty() || memberName.length() > DBUS_MAXIMUM_NAME_LENGTH)
return false;
- QRegExp regex("[a-zA-Z0-9_]+");
+ QRegExp regex(QLatin1String("[a-zA-Z_][a-zA-Z0-9_]+"));
return regex.exactMatch(memberName);
}
+ /*!
+ Returns true if \p errorName is a valid error name. Valid error names are valid interface
+ names and vice-versa, so this function is actually an alias for isValidInterfaceName.
+ */
bool isValidErrorName(const QString &errorName)
{
return isValidInterfaceName(errorName);
}
+ /*!
+ Returns true if \p path is valid object path.
+
+ Valid object paths follow the rules:
+ - start with the slash character ("/")
+ - do not end in a slash, unless the path is just the initial slash
+ - do not contain any two slashes in sequence
+ - contain slash-separated parts, each of which is composed of ASCII letters, digits and
+ underscores ("_")
+ */
bool isValidObjectPath(const QString &path)
{
if (path == QLatin1String("/"))
return true;
- if (!path.startsWith('/') || path.indexOf(QLatin1String("//")) != -1 ||
- path.endsWith('/'))
+ if (!path.startsWith(QLatin1Char('/')) || path.indexOf(QLatin1String("//")) != -1 ||
+ path.endsWith(QLatin1Char('/')))
return false;
- QStringList parts = path.split('/');
+ QStringList parts = path.split(QLatin1Char('/'));
Q_ASSERT(parts.count() >= 1);
parts.removeFirst(); // it starts with /, so we get an empty first part
-
- QRegExp regex("[a-zA-Z0-9_]+");
+
+ QRegExp regex(QLatin1String("[a-zA-Z0-9_]+"));
foreach (QString part, parts)
if (!regex.exactMatch(part))
return false;
@@ -120,14 +166,26 @@ namespace QDBusUtil
return true;
}
+ /*!
+ Returns true if \p signature is a valid D-Bus type signature for one or more types.
+ This function returns true if it can all of \p signature into valid, individual types and no
+ characters remain in \p signature.
+
+ \see isValidSingleSignature
+ */
bool isValidSignature(const QString &signature)
{
return dbus_signature_validate(signature.toUtf8(), 0);
}
+ /*!
+ Returns true if \p signature is a valid D-Bus type signature for exactly one full type. This
+ function tries to convert the type signature into a D-Bus type and, if it succeeds and no
+ characters remain in the signature, it returns true.
+ */
bool isValidSingleSignature(const QString &signature)
{
return dbus_signature_validate_single(signature.toUtf8(), 0);
}
-
+
} // namespace QDBusUtil