From 06ac9e18cb1931b2091d7c4123dfc89dd133719f Mon Sep 17 00:00:00 2001 From: "Sergio R. Caprile" Date: Tue, 30 May 2023 12:26:58 -0300 Subject: [PATCH] fix qos=2 handling --- mongoose.c | 6 ++++-- src/mqtt.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/mongoose.c b/mongoose.c index adfe4a19..68724c43 100644 --- a/mongoose.c +++ b/mongoose.c @@ -3376,7 +3376,9 @@ static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data, uint32_t remaining_len = sizeof(id); if (c->is_mqtt5) remaining_len += 1; - mg_mqtt_send_header(c, MQTT_CMD_PUBACK, 0, remaining_len); + mg_mqtt_send_header( + c, mm.qos == 2 ? MQTT_CMD_PUBREC : MQTT_CMD_PUBACK, 0, + remaining_len); mg_send(c, &id, sizeof(id)); if (c->is_mqtt5) { @@ -3384,7 +3386,7 @@ static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data, mg_send(c, &zero, sizeof(zero)); } } - mg_call(c, MG_EV_MQTT_MSG, &mm); + mg_call(c, MG_EV_MQTT_MSG, &mm); // let the app handle qos2 stuff break; } } diff --git a/src/mqtt.c b/src/mqtt.c index 50f6aaee..a585aff1 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -449,7 +449,9 @@ static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data, uint32_t remaining_len = sizeof(id); if (c->is_mqtt5) remaining_len += 1; - mg_mqtt_send_header(c, MQTT_CMD_PUBACK, 0, remaining_len); + mg_mqtt_send_header( + c, mm.qos == 2 ? MQTT_CMD_PUBREC : MQTT_CMD_PUBACK, 0, + remaining_len); mg_send(c, &id, sizeof(id)); if (c->is_mqtt5) { @@ -457,7 +459,7 @@ static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data, mg_send(c, &zero, sizeof(zero)); } } - mg_call(c, MG_EV_MQTT_MSG, &mm); + mg_call(c, MG_EV_MQTT_MSG, &mm); // let the app handle qos2 stuff break; } }