From b462115fa6d07dfa9848e5d6268176aaa9d8f5b1 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 31 Oct 2018 08:24:28 +0000 Subject: [PATCH] Add reason code to PUBACK/REC/REL/COMP. --- lib/send_mosq.c | 14 ++++++++------ lib/send_mosq.h | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/send_mosq.c b/lib/send_mosq.c index a29d0919..9bf441a1 100644 --- a/lib/send_mosq.c +++ b/lib/send_mosq.c @@ -73,7 +73,7 @@ int send__puback(struct mosquitto *mosq, uint16_t mid) if(mosq) log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s sending PUBACK (Mid: %d)", mosq->id, mid); #endif /* We don't use Reason String or User Property yet. */ - return send__command_with_mid(mosq, CMD_PUBACK, mid, false, NULL); + return send__command_with_mid(mosq, CMD_PUBACK, mid, false, 0, NULL); } int send__pubcomp(struct mosquitto *mosq, uint16_t mid) @@ -84,7 +84,7 @@ int send__pubcomp(struct mosquitto *mosq, uint16_t mid) if(mosq) log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s sending PUBCOMP (Mid: %d)", mosq->id, mid); #endif /* We don't use Reason String or User Property yet. */ - return send__command_with_mid(mosq, CMD_PUBCOMP, mid, false, NULL); + return send__command_with_mid(mosq, CMD_PUBCOMP, mid, false, 0, NULL); } @@ -96,7 +96,7 @@ int send__pubrec(struct mosquitto *mosq, uint16_t mid) if(mosq) log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s sending PUBREC (Mid: %d)", mosq->id, mid); #endif /* We don't use Reason String or User Property yet. */ - return send__command_with_mid(mosq, CMD_PUBREC, mid, false, NULL); + return send__command_with_mid(mosq, CMD_PUBREC, mid, false, 0, NULL); } int send__pubrel(struct mosquitto *mosq, uint16_t mid) @@ -107,11 +107,11 @@ int send__pubrel(struct mosquitto *mosq, uint16_t mid) if(mosq) log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s sending PUBREL (Mid: %d)", mosq->id, mid); #endif /* We don't use Reason String or User Property yet. */ - return send__command_with_mid(mosq, CMD_PUBREL|2, mid, false, NULL); + return send__command_with_mid(mosq, CMD_PUBREL|2, mid, false, 0, NULL); } /* For PUBACK, PUBCOMP, PUBREC, and PUBREL */ -int send__command_with_mid(struct mosquitto *mosq, uint8_t command, uint16_t mid, bool dup, struct mqtt5__property *properties) +int send__command_with_mid(struct mosquitto *mosq, uint8_t command, uint16_t mid, bool dup, uint8_t reason_code, struct mqtt5__property *properties) { struct mosquitto__packet *packet = NULL; int rc; @@ -130,7 +130,8 @@ int send__command_with_mid(struct mosquitto *mosq, uint8_t command, uint16_t mid if(mosq->protocol == mosq_p_mqtt5){ proplen = property__get_length_all(properties); varbytes = packet__varint_bytes(proplen); - packet->remaining_length += varbytes + proplen; + /* 1 here is sizeof(reason_code) */ + packet->remaining_length += 1 + varbytes + proplen; } rc = packet__alloc(packet); @@ -142,6 +143,7 @@ int send__command_with_mid(struct mosquitto *mosq, uint8_t command, uint16_t mid packet__write_uint16(packet, mid); if(mosq->protocol == mosq_p_mqtt5){ + packet__write_byte(packet, reason_code); property__write_all(packet, properties); } diff --git a/lib/send_mosq.h b/lib/send_mosq.h index 7ea0b12b..34b1b878 100644 --- a/lib/send_mosq.h +++ b/lib/send_mosq.h @@ -20,7 +20,7 @@ Contributors: #include "property_mosq.h" int send__simple_command(struct mosquitto *mosq, uint8_t command); -int send__command_with_mid(struct mosquitto *mosq, uint8_t command, uint16_t mid, bool dup, struct mqtt5__property *properties); +int send__command_with_mid(struct mosquitto *mosq, uint8_t command, uint16_t mid, bool dup, uint8_t reason_code, struct mqtt5__property *properties); int send__real_publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, int qos, bool retain, bool dup, struct mqtt5__property *properties); int send__connect(struct mosquitto *mosq, uint16_t keepalive, bool clean_session);