From 7c4cc01e83f6f9936204be1d7032c68b64d47bda Mon Sep 17 00:00:00 2001 From: Flavio Fernandes Date: Sun, 4 Mar 2018 11:36:25 -0500 Subject: [PATCH] Adafruit_MQTT (API): the payload of publish method is read-only The payload param provided in publish is a const. This change fixes the API to ensure caller that this is the case for all variations of the publish method. --- Adafruit_MQTT.cpp | 8 ++++---- Adafruit_MQTT.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Adafruit_MQTT.cpp b/Adafruit_MQTT.cpp index 0b025db..a5d8bb6 100644 --- a/Adafruit_MQTT.cpp +++ b/Adafruit_MQTT.cpp @@ -311,10 +311,10 @@ bool Adafruit_MQTT::disconnect() { } bool Adafruit_MQTT::publish(const char *topic, const char *data, uint8_t qos) { - return publish(topic, (uint8_t *)(data), strlen(data), qos); + return publish(topic, (const uint8_t *)(data), strlen(data), qos); } -bool Adafruit_MQTT::publish(const char *topic, uint8_t *data, uint16_t bLen, +bool Adafruit_MQTT::publish(const char *topic, const uint8_t *data, uint16_t bLen, uint8_t qos) { // Construct and send publish packet. uint16_t len = publishPacket(buffer, topic, data, bLen, qos, @@ -678,7 +678,7 @@ uint16_t Adafruit_MQTT::packetAdditionalLen(uint16_t currLen) // as per // http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718040 uint16_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic, - uint8_t *data, uint16_t bLen, + const uint8_t *data, uint16_t bLen, uint8_t qos, uint16_t maxPacketLen) { uint8_t *p = packet; uint16_t len = 0; @@ -855,7 +855,7 @@ bool Adafruit_MQTT_Publish::publish(const char *payload) { } // publish buffer of arbitrary length -bool Adafruit_MQTT_Publish::publish(uint8_t *payload, uint16_t bLen) { +bool Adafruit_MQTT_Publish::publish(const uint8_t *payload, uint16_t bLen) { return mqtt->publish(topic, payload, bLen, qos); } diff --git a/Adafruit_MQTT.h b/Adafruit_MQTT.h index 8944864..44eb350 100644 --- a/Adafruit_MQTT.h +++ b/Adafruit_MQTT.h @@ -187,7 +187,7 @@ class Adafruit_MQTT { // Publish a message to a topic using the specified QoS level. Returns true // if the message was published, false otherwise. bool publish(const char *topic, const char *payload, uint8_t qos = 0); - bool publish(const char *topic, uint8_t *payload, uint16_t bLen, + bool publish(const char *topic, const uint8_t *payload, uint16_t bLen, uint8_t qos = 0); // Add a subscription to receive messages for a topic. Returns true if the @@ -258,7 +258,7 @@ class Adafruit_MQTT { uint8_t connectPacket(uint8_t *packet); uint8_t disconnectPacket(uint8_t *packet); static uint16_t packetAdditionalLen(uint16_t currLen); - uint16_t publishPacket(uint8_t *packet, const char *topic, uint8_t *payload, + uint16_t publishPacket(uint8_t *packet, const char *topic, const uint8_t *payload, uint16_t bLen, uint8_t qos, uint16_t maxPacketLen); uint8_t subscribePacket(uint8_t *packet, const char *topic, uint8_t qos); uint8_t unsubscribePacket(uint8_t *packet, const char *topic); @@ -279,7 +279,7 @@ class Adafruit_MQTT_Publish { // This might be ignored and a higher precision value sent. bool publish(int32_t i); bool publish(uint32_t i); - bool publish(uint8_t *b, uint16_t bLen); + bool publish(const uint8_t *b, uint16_t bLen); private: Adafruit_MQTT *mqtt;