eclipse / paho.mqtt.embedded-c

Paho MQTT C client library for embedded systems. Paho is an Eclipse IoT project (https://iot.eclipse.org/)

Home Page:https://eclipse.org/paho

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

isTopicMatched() does not behave correctly for filter that terminates with wildcard /#

hgrf opened this issue · comments

This can be observed for example with Google IoT Core, which requires the client to subscribe to the topic /devices/{device-id}/commands/# (see https://cloud.google.com/iot/docs/how-tos/commands#receiving_a_command).

When a message is now sent to the device - but on the topic /devices/{device-id}/commands (without wildcard or any subtopic), the function isTopicMatched() does not correctly identify the match.

A quick and dirty solution:

return (curn == curn_end) && (*curf == '\0');

=>

return (curn == curn_end) && ((*curf == '\0') || ((curf[0] == '/') && (curf[1] == '#') && (curf[2] == '\0')));

(I think this has been raised before: #117)

OASIS spec 3.1.1 section 4.7.1.2 has the following non-normative comment: “sport/#” also matches the singular “sport”, since # includes the parent level.
This is not occurring. Since that is non-normative, and AFAIK Mosquitto and probably many other implementations also do the same, I suggest you also subscribe to '/devices/123-45/commands' if that is what you need. Perhaps you can also publish to '/devices/123-45/commands/cmdname', it's been a while since I played with GCP.

Mosquitto version 1.6.10 running on libmosquitto 1.6.10:

$ mosquitto_sub -t /devices/123-45/commands/# -h mqtt.lab -v &
$ mosquitto_pub -t /devices/123-45/commands/thiscmd -h mqtt.lab -m "This message"
/devices/123-45/commands/thiscmd This message
$ mosquitto_pub -t /devices/123-45/commands -h mqtt.lab -m "This message"
$

Thanks for the quick reply and the reference to the standard.