Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hgrf opened this issue Oct 28, 2021 · 2 comments

Comments

@hgrf
Copy link

hgrf commented Oct 28, 2021

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:

https://github.com/eclipse/paho.mqtt.embedded-c/blob/29ab2aa29c5e47794284376d7f8386cfd54c3eed/MQTTClient-C/src/MQTTClient.c#L175
=>

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

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

@scaprile
Copy link
Contributor

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"
$

@hgrf
Copy link
Author

hgrf commented Oct 28, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants