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

v5 headers missing for QoS 2 subscription #1432

Closed
magnusga opened this issue Sep 26, 2019 · 3 comments
Closed

v5 headers missing for QoS 2 subscription #1432

magnusga opened this issue Sep 26, 2019 · 3 comments

Comments

@magnusga
Copy link

Hi! :)

MQTT v5 headers seems to be missing when I publish and subscribe to messages with QoS 2. However, QoS 0 and 1 works fine. Don't know if this is a problem with the mosquitto broker, or with the client library.

Using mosquitto 1.6.7 Windows x64. Compiling with Visual Studio Community 2017 compiler in a Qt project.

Here's the callback for the client:

void message_v5_callback(struct mosquitto *mosq, void *, const struct mosquitto_message *message, const mosquitto_property *proplist)
{
    char *contentType = nullptr;
    char *responseTopic = nullptr;

    printf("\n");
    printf("QoS: %i\n", message->qos);
    printf("Topic: %s\n", message->topic);

    if (mosquitto_property_read_string(proplist, MQTT_PROP_CONTENT_TYPE, &contentType, false))
    {
        printf("Content-type: %s\n", contentType);
//        free(contentType);
    }

    if (mosquitto_property_read_string(proplist, MQTT_PROP_RESPONSE_TOPIC, &responseTopic, false))
    {
        printf("Response-topic: %s\n", responseTopic);
//        free(responseTopic);
    }

    printf("%.*s\n", message->payloadlen, static_cast<const char *>(message->payload));
}

Here's the publish command:

mosquitto_pub -V 5 -D publish content-type text/plain -D publish response-topic msg/123 -t msg -m hello -q 2

Here are the results for QoS 0, 1 and 2:


QoS: 0
Topic: msg
Content-type: text/plain
Response-topic: msg/123
hello

QoS: 1
Topic: msg
Content-type: text/plain
Response-topic: msg/123
hello

QoS: 2
Topic: msg
hello

QoS 2 is missing headers for content-type and response-topic. Is this a bug in mosquitto? Can anyone reproduce this?

(Unrelated: "free()" has been commented out in the above code snippet because it was causing the program to crash. Don't know if that is a Qt specific problem or what.)

ralight added a commit that referenced this issue Sep 26, 2019
@ralight
Copy link
Contributor

ralight commented Sep 26, 2019

Thanks for the detailed report, this was a bug which is now fixed in the fixes branch. Please feel free to give it a try.

With regards the free causing problems - I haven't been able to reproduce that in my simple command line only test programs. If you still have that problem I'd be interested in making sure it isn't something in the library.

@magnusga
Copy link
Author

Nice! Thank you! I will test it on Monday. And regarding free, I will do some more tests on Monday as well. Compile without Qt etc. And open a new issue if it's relevant.

@magnusga
Copy link
Author

I have tested it on my setup, and it works great. Also the free issue disappeared when compiling mosquitto myself (instead of using the precompiled installer).

@lock lock bot locked as resolved and limited conversation to collaborators Dec 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants