diff --git a/src/bluetooth/bluez/bluez5_helper.cpp b/src/bluetooth/bluez/bluez5_helper.cpp index 384b9979308a8219c71fb1d2f74df8fb4a7bba05..14e064e12551d312e2e2a187cbb56b700b32633c 100644 --- a/src/bluetooth/bluez/bluez5_helper.cpp +++ b/src/bluetooth/bluez/bluez5_helper.cpp @@ -339,4 +339,26 @@ QString findAdapterForAddress(const QBluetoothAddress &wantedAddress, bool *ok = return QString(); // nothing matching found } +/* + Removes every character that cannot be used in QDbusObjectPath + + See QDbusUtil::isValidObjectPath(QString) for more details. + */ +QString sanitizeNameForDBus(const QString &text) +{ + QString appName = text; + for (int i = 0; i < appName.length(); i++) { + ushort us = appName[i].unicode(); + bool valid = (us >= 'a' && us <= 'z') + || (us >= 'A' && us <= 'Z') + || (us >= '0' && us <= '9') + || (us == '_'); + + if (!valid) + appName[i] = QLatin1Char('_'); + } + + return appName; +} + QT_END_NAMESPACE diff --git a/src/bluetooth/bluez/bluez5_helper_p.h b/src/bluetooth/bluez/bluez5_helper_p.h index a3f164b0518a16dbbdec4eced9232569065eb510..019fe63597bfc28ce4b9309b46f6518a0b04af9c 100644 --- a/src/bluetooth/bluez/bluez5_helper_p.h +++ b/src/bluetooth/bluez/bluez5_helper_p.h @@ -59,6 +59,8 @@ QT_BEGIN_NAMESPACE bool isBluez5(); +QString sanitizeNameForDBus(const QString& text); + QString findAdapterForAddress(const QBluetoothAddress &wantedAddress, bool *ok); class QtBluezDiscoveryManagerPrivate; diff --git a/src/bluetooth/qbluetoothserviceinfo_bluez.cpp b/src/bluetooth/qbluetoothserviceinfo_bluez.cpp index e3fa81d117a8ad6a893ffa6e80388e1ea1b9c3f4..d18f4bb13ccec79d944507d9734242080c314026 100644 --- a/src/bluetooth/qbluetoothserviceinfo_bluez.cpp +++ b/src/bluetooth/qbluetoothserviceinfo_bluez.cpp @@ -294,7 +294,7 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca // create path profilePath = profilePathTemplate; profilePath.append(QString::fromLatin1("/%1%2/%3"). - arg(QCoreApplication::applicationName()). + arg(sanitizeNameForDBus(QCoreApplication::applicationName())). arg(QCoreApplication::applicationPid()). arg(pathCounter.fetchAndAddOrdered(1))); diff --git a/src/bluetooth/qbluetoothtransferreply_bluez.cpp b/src/bluetooth/qbluetoothtransferreply_bluez.cpp index f7f72873532f418654a5d93d4126929ec2e12827..3362b2c19db11ac47f96c1e2e92f461885a79ada 100644 --- a/src/bluetooth/qbluetoothtransferreply_bluez.cpp +++ b/src/bluetooth/qbluetoothtransferreply_bluez.cpp @@ -91,7 +91,7 @@ QBluetoothTransferReplyBluez::QBluetoothTransferReplyBluez(QIODevice *input, con m_agent_path = agentPath; m_agent_path.append(QStringLiteral("/%1%2/%3"). - arg(QCoreApplication::applicationName()). + arg(sanitizeNameForDBus(QCoreApplication::applicationName())). arg(QCoreApplication::applicationPid()). arg(agentPathCounter.fetchAndAddOrdered(1)));