Commit 9d3e7e9c authored by Alex Blasche's avatar Alex Blasche
Browse files

Bluez5: Sanitize app name to be valid DBus object path name


This may happen when the app name contains for example a dash ('-').

Task-number: QTBUG-49402
Change-Id: I04b289b0723e2979a67c93e335205556bf1eb30e
Reviewed-by: default avatarTimur Pocheptsov <timur.pocheptsov@theqtcompany.com>
Showing with 26 additions and 2 deletions
...@@ -339,4 +339,26 @@ QString findAdapterForAddress(const QBluetoothAddress &wantedAddress, bool *ok = ...@@ -339,4 +339,26 @@ QString findAdapterForAddress(const QBluetoothAddress &wantedAddress, bool *ok =
return QString(); // nothing matching found 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 QT_END_NAMESPACE
...@@ -59,6 +59,8 @@ QT_BEGIN_NAMESPACE ...@@ -59,6 +59,8 @@ QT_BEGIN_NAMESPACE
bool isBluez5(); bool isBluez5();
QString sanitizeNameForDBus(const QString& text);
QString findAdapterForAddress(const QBluetoothAddress &wantedAddress, bool *ok); QString findAdapterForAddress(const QBluetoothAddress &wantedAddress, bool *ok);
class QtBluezDiscoveryManagerPrivate; class QtBluezDiscoveryManagerPrivate;
......
...@@ -294,7 +294,7 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca ...@@ -294,7 +294,7 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca
// create path // create path
profilePath = profilePathTemplate; profilePath = profilePathTemplate;
profilePath.append(QString::fromLatin1("/%1%2/%3"). profilePath.append(QString::fromLatin1("/%1%2/%3").
arg(QCoreApplication::applicationName()). arg(sanitizeNameForDBus(QCoreApplication::applicationName())).
arg(QCoreApplication::applicationPid()). arg(QCoreApplication::applicationPid()).
arg(pathCounter.fetchAndAddOrdered(1))); arg(pathCounter.fetchAndAddOrdered(1)));
......
...@@ -91,7 +91,7 @@ QBluetoothTransferReplyBluez::QBluetoothTransferReplyBluez(QIODevice *input, con ...@@ -91,7 +91,7 @@ QBluetoothTransferReplyBluez::QBluetoothTransferReplyBluez(QIODevice *input, con
m_agent_path = agentPath; m_agent_path = agentPath;
m_agent_path.append(QStringLiteral("/%1%2/%3"). m_agent_path.append(QStringLiteral("/%1%2/%3").
arg(QCoreApplication::applicationName()). arg(sanitizeNameForDBus(QCoreApplication::applicationName())).
arg(QCoreApplication::applicationPid()). arg(QCoreApplication::applicationPid()).
arg(agentPathCounter.fetchAndAddOrdered(1))); arg(agentPathCounter.fetchAndAddOrdered(1)));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment