summaryrefslogtreecommitdiffstats
path: root/src/dbus/qdbusutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/dbus/qdbusutil.cpp')
-rw-r--r--src/dbus/qdbusutil.cpp68
1 files changed, 28 insertions, 40 deletions
diff --git a/src/dbus/qdbusutil.cpp b/src/dbus/qdbusutil.cpp
index 7390e8d7a4..827418c487 100644
--- a/src/dbus/qdbusutil.cpp
+++ b/src/dbus/qdbusutil.cpp
@@ -7,6 +7,7 @@
#include <QtCore/qlist.h>
#include <QtCore/qstringlist.h>
+#include <private/qtools_p.h>
#include "qdbusargument.h"
#include "qdbusunixfiledescriptor.h"
@@ -16,29 +17,24 @@
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
+using namespace QtMiscUtils;
static inline bool isValidCharacterNoDash(QChar c)
{
ushort u = c.unicode();
- return (u >= 'a' && u <= 'z')
- || (u >= 'A' && u <= 'Z')
- || (u >= '0' && u <= '9')
- || (u == '_');
+ return isAsciiLetterOrNumber(u) || (u == '_');
}
static inline bool isValidCharacter(QChar c)
{
ushort u = c.unicode();
- return (u >= 'a' && u <= 'z')
- || (u >= 'A' && u <= 'Z')
- || (u >= '0' && u <= '9')
+ return isAsciiLetterOrNumber(u)
|| (u == '_') || (u == '-');
}
static inline bool isValidNumber(QChar c)
{
- ushort u = c.unicode();
- return (u >= '0' && u <= '9');
+ return (isAsciiDigit(c.toLatin1()));
}
#ifndef QT_BOOTSTRAPPED
@@ -210,6 +206,21 @@ static const char oneLetterTypes[] = "vsogybnqiuxtdh";
static const char basicTypes[] = "sogybnqiuxtdh";
static const char fixedTypes[] = "ybnqiuxtdh";
+/*
+ D-Bus signature grammar (in ABNF), as of 0.42 (2023-08-21):
+ https://dbus.freedesktop.org/doc/dbus-specification.html#type-system
+
+ <signature> = *<single-complete-type>
+ <single-complete-type> = <basic-type> / <variant> / <struct> / <array>
+ <fixed-type> = "y" / "b" / "n" / "q" / "i" / "u" / "x" / "t" / "d" / "h"
+ <variable-length-type> = "s" / "o" / "g"
+ <basic-type> = <variable-length-type> / <fixed-type>
+ <variant> = "v"
+ <struct> = "(" 1*<single-complete-type> ")"
+ <array> = "a" ( <single-complete-type> / <dict-entry> )
+ <dict-entry> = "{" <basic-type> <single-complete-type> "}"
+*/
+
static bool isBasicType(int c)
{
return c != DBUS_TYPE_INVALID && strchr(basicTypes, c) != nullptr;
@@ -306,7 +317,7 @@ namespace QDBusUtil
return false; // can't be valid if it's empty
const QChar *c = part.data();
- for (int i = 0; i < part.length(); ++i)
+ for (int i = 0; i < part.size(); ++i)
if (!isValidCharacterNoDash(c[i]))
return false;
@@ -314,13 +325,6 @@ namespace QDBusUtil
}
/*!
- \internal
- \fn bool isValidPartOfObjectPath(const QString &part)
-
- \overload
- */
-
- /*!
\fn bool isValidInterfaceName(const QString &ifaceName)
Returns \c true if this is \a ifaceName is a valid interface name.
@@ -358,7 +362,7 @@ namespace QDBusUtil
*/
bool isValidUniqueConnectionName(QStringView connName)
{
- if (connName.isEmpty() || connName.length() > DBUS_MAXIMUM_NAME_LENGTH ||
+ if (connName.isEmpty() || connName.size() > DBUS_MAXIMUM_NAME_LENGTH ||
!connName.startsWith(u':'))
return false;
@@ -371,7 +375,7 @@ namespace QDBusUtil
return false;
const QChar* c = part.data();
- for (int j = 0; j < part.length(); ++j)
+ for (int j = 0; j < part.size(); ++j)
if (!isValidCharacter(c[j]))
return false;
}
@@ -380,12 +384,6 @@ namespace QDBusUtil
}
/*!
- \fn bool isValidUniqueConnectionName(const QString &connName)
-
- \overload
- */
-
- /*!
\fn bool isValidBusName(const QString &busName)
Returns \c true if \a busName is a valid bus name.
@@ -409,9 +407,6 @@ namespace QDBusUtil
return isValidUniqueConnectionName(busName);
const auto parts = QStringView{busName}.split(u'.');
- if (parts.size() < 1)
- return false;
-
for (QStringView part : parts) {
if (part.isEmpty())
return false;
@@ -419,7 +414,7 @@ namespace QDBusUtil
const QChar *c = part.data();
if (isValidNumber(c[0]))
return false;
- for (int j = 0; j < part.length(); ++j)
+ for (int j = 0; j < part.size(); ++j)
if (!isValidCharacter(c[j]))
return false;
}
@@ -435,25 +430,19 @@ namespace QDBusUtil
*/
bool isValidMemberName(QStringView memberName)
{
- if (memberName.isEmpty() || memberName.length() > DBUS_MAXIMUM_NAME_LENGTH)
+ if (memberName.isEmpty() || memberName.size() > DBUS_MAXIMUM_NAME_LENGTH)
return false;
const QChar* c = memberName.data();
if (isValidNumber(c[0]))
return false;
- for (int j = 0; j < memberName.length(); ++j)
+ for (int j = 0; j < memberName.size(); ++j)
if (!isValidCharacterNoDash(c[j]))
return false;
return true;
}
/*!
- \fn bool isValidMemberName(const QString &memberName)
-
- \overload
- */
-
- /*!
\fn bool isValidErrorName(const QString &errorName)
Returns \c true if \a 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.
@@ -471,9 +460,8 @@ namespace QDBusUtil
\list
\li start with the slash character ("/")
\li do not end in a slash, unless the path is just the initial slash
- \li do not contain any two slashes in sequence
- \li contain slash-separated parts, each of which is composed of ASCII letters, digits and
- underscores ("_")
+ \li contain slash-separated parts, each of which is not empty, and composed
+ only of ASCII letters, digits and underscores ("_").
\endlist
*/
bool isValidObjectPath(const QString &path)