diff options
Diffstat (limited to 'src/dbus/qdbusutil.cpp')
-rw-r--r-- | src/dbus/qdbusutil.cpp | 86 |
1 files changed, 37 insertions, 49 deletions
diff --git a/src/dbus/qdbusutil.cpp b/src/dbus/qdbusutil.cpp index 4770d25e99..78338aa054 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 @@ -59,7 +55,7 @@ static bool variantToString(const QVariant &arg, QString &out) } else if (argType == QMetaType::QByteArray) { out += u'{'; QByteArray list = arg.toByteArray(); - for (int i = 0; i < list.length(); ++i) { + for (int i = 0; i < list.size(); ++i) { out += QString::number(list.at(i)); out += ", "_L1; } @@ -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. @@ -335,11 +339,11 @@ namespace QDBusUtil */ bool isValidInterfaceName(const QString& ifaceName) { - if (ifaceName.isEmpty() || ifaceName.length() > DBUS_MAXIMUM_NAME_LENGTH) + if (ifaceName.isEmpty() || ifaceName.size() > DBUS_MAXIMUM_NAME_LENGTH) return false; const auto parts = QStringView{ifaceName}.split(u'.'); - if (parts.count() < 2) + if (parts.size() < 2) return false; // at least two parts for (auto part : parts) @@ -358,12 +362,12 @@ 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; const auto parts = connName.mid(1).split(u'.'); - if (parts.count() < 1) + if (parts.size() < 1) return false; for (QStringView part : parts) { @@ -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. @@ -402,16 +400,13 @@ namespace QDBusUtil */ bool isValidBusName(const QString &busName) { - if (busName.isEmpty() || busName.length() > DBUS_MAXIMUM_NAME_LENGTH) + if (busName.isEmpty() || busName.size() > DBUS_MAXIMUM_NAME_LENGTH) return false; if (busName.startsWith(u':')) return isValidUniqueConnectionName(busName); const auto parts = QStringView{busName}.split(u'.'); - if (parts.count() < 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) @@ -524,14 +512,14 @@ namespace QDBusUtil bool isValidSignature(const QString &signature) { QByteArray ba = signature.toLatin1(); - const char *data = ba.constData(); - while (true) { + const char *data = ba.constBegin(); + const char *end = ba.constEnd(); + while (data != end) { data = validateSingleType(data); if (!data) return false; - if (*data == '\0') - return true; } + return true; } /*! |