Commit 60ac1cde91c67f666fe78b670abc3a6fea6f44f9
1 parent
cf0166d6
[Fix] Bugfix in hasWildcard
Showing
2 changed files
with
22 additions
and
2 deletions
src/mqttclient.cpp
... | ... | @@ -215,9 +215,17 @@ void MqttClient::disconnect() |
215 | 215 | |
216 | 216 | Token MqttClient::publish(const MqttMessage& message, int qos) |
217 | 217 | { |
218 | - if (hasWildcard(message.topic()) || !isValidTopic(message.topic())) { | |
218 | + if (hasWildcard(message.topic())) | |
219 | + { | |
220 | + LogDebug("[MqttClient::publish]","Topic has wildcard : " + message.topic()); | |
219 | 221 | return Token(m_clientId, -1); |
220 | 222 | } |
223 | + else if(!isValidTopic(message.topic())) | |
224 | + { | |
225 | + LogDebug("[MqttClient::publish]","Topic is invalid : " + message.topic()); | |
226 | + return Token(m_clientId, -1); | |
227 | + } | |
228 | + | |
221 | 229 | OSDEV_COMPONENTS_LOCKGUARD(m_interfaceMutex); |
222 | 230 | IMqttClientImpl* client(nullptr); |
223 | 231 | { |
... | ... | @@ -239,6 +247,13 @@ Token MqttClient::publish(const MqttMessage& message, int qos) |
239 | 247 | } |
240 | 248 | client = m_principalClient.get(); |
241 | 249 | } |
250 | + | |
251 | + if(!client) | |
252 | + { | |
253 | + LogDebug("[MqttClient::publish]", "Invalid pointer to IMqttClient retrieved."); | |
254 | + return Token(m_clientId, -1); | |
255 | + } | |
256 | + | |
242 | 257 | return Token(client->clientId(), client->publish(message, qos)); |
243 | 258 | } |
244 | 259 | ... | ... |
src/mqttutil.cpp
... | ... | @@ -55,7 +55,12 @@ bool isValidTopic( const std::string &topic ) |
55 | 55 | |
56 | 56 | bool hasWildcard( const std::string &topic ) |
57 | 57 | { |
58 | - return ( topic.size() > 0 && (topic.find( '+' ) != std::string::npos || topic.size() - 1 == '#' ) ); | |
58 | + return ( topic.size() > 0 && | |
59 | + ( | |
60 | + topic.find( '+' ) != std::string::npos || | |
61 | + topic.back() == '#' | |
62 | + ) | |
63 | + ); | |
59 | 64 | } |
60 | 65 | |
61 | 66 | bool testForOverlap( const std::string &existingTopic, const std::string &newTopic ) | ... | ... |