Commit b0a1e8a4 authored by Ian Craggs's avatar Ian Craggs

Ensure QoS 2 messages are only delivered once for MQTT V5 #476

parent 0c3837fa
...@@ -294,9 +294,11 @@ int MQTTProtocol_handlePublishes(void* pack, int sock) ...@@ -294,9 +294,11 @@ int MQTTProtocol_handlePublishes(void* pack, int sock)
{ {
/* store publication in inbound list */ /* store publication in inbound list */
int len; int len;
int already_received = 0;
ListElement* listElem = NULL; ListElement* listElem = NULL;
Messages* m = malloc(sizeof(Messages)); Messages* m = malloc(sizeof(Messages));
Publications* p = MQTTProtocol_storePublication(publish, &len); Publications* p = MQTTProtocol_storePublication(publish, &len);
m->publish = p; m->publish = p;
m->msgid = publish->msgId; m->msgid = publish->msgId;
m->qos = publish->header.bits.qos; m->qos = publish->header.bits.qos;
...@@ -313,10 +315,11 @@ int MQTTProtocol_handlePublishes(void* pack, int sock) ...@@ -313,10 +315,11 @@ int MQTTProtocol_handlePublishes(void* pack, int sock)
MQTTProperties_free(&msg->properties); MQTTProperties_free(&msg->properties);
ListInsert(client->inboundMsgs, m, sizeof(Messages) + len, listElem); ListInsert(client->inboundMsgs, m, sizeof(Messages) + len, listElem);
ListRemove(client->inboundMsgs, msg); ListRemove(client->inboundMsgs, msg);
already_received = 1;
} else } else
ListAppend(client->inboundMsgs, m, sizeof(Messages) + len); ListAppend(client->inboundMsgs, m, sizeof(Messages) + len);
rc = MQTTPacket_send_pubrec(publish->msgId, &client->net, client->clientID); rc = MQTTPacket_send_pubrec(publish->msgId, &client->net, client->clientID);
if (m->MQTTVersion >= MQTTVERSION_5) if (m->MQTTVersion >= MQTTVERSION_5 && already_received == 0)
{ {
publish->payload = m->publish->payload; publish->payload = m->publish->payload;
Protocol_processPublication(publish, client); Protocol_processPublication(publish, client);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment