diff options
Diffstat (limited to 'src/mqtt/qmqtttopicfilter.cpp')
-rw-r--r-- | src/mqtt/qmqtttopicfilter.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/mqtt/qmqtttopicfilter.cpp b/src/mqtt/qmqtttopicfilter.cpp index d2071c7..1e6bd9c 100644 --- a/src/mqtt/qmqtttopicfilter.cpp +++ b/src/mqtt/qmqtttopicfilter.cpp @@ -154,6 +154,24 @@ void QMqttTopicFilter::setFilter(const QString &filter) } /*! + \since 5.12 + + Returns the name of a share if the topic filter has been specified as + a shared subscription. The format of shared subscriptions is defined + as \c $share/sharename/topicfilter. +*/ +QString QMqttTopicFilter::shareName() const +{ + QString result; + if (d->filter.startsWith(QLatin1String("$share/"))) { + // Has to have at least two / + // $share/<sharename>/topicfilter + result = d->filter.section(QLatin1Char('/'), 1, 1); + } + return result; +} + +/*! Returns \c true if the topic filter is valid according to the MQTT standard section 4.7, or \c false otherwise. */ @@ -184,6 +202,13 @@ bool QMqttTopicFilter::isValid() const singleLevelPosition = d->filter.indexOf(QLatin1Char('#'), singleLevelPosition + 1); } + // Shared Subscription syntax + // $share/shareName/TopicFilter -- must have at least 2 '/' + if (d->filter.startsWith(QLatin1String("$share/"))) { + const int index = d->filter.indexOf(QLatin1Char('/'), 7); + if (index == -1 || index == 7) + return false; + } return true; } |