From a780728da767b4648d1f9f52135d58d5f7465fee 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 59fd9d9..0180d05 100644 --- a/Adafruit_MQTT.cpp +++ b/Adafruit_MQTT.cpp @@ -298,10 +298,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, uint8_t qos) { +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, (uint16_t) sizeof(buffer), topic, data, bLen, qos); if (!sendPacket(buffer, len)) @@ -648,7 +648,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, uint16_t maxPacketLen, const char *topic, - uint8_t *data, uint16_t bLen, uint8_t qos) { + const uint8_t *data, uint16_t bLen, uint8_t qos) { uint8_t *p = packet; uint16_t len=2; // control + length @@ -825,7 +825,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 6c1daec..a7aac17 100644 --- a/Adafruit_MQTT.h +++ b/Adafruit_MQTT.h @@ -178,7 +178,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, uint8_t qos = 0); + 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 // subscription could be added or was already present, false otherwise. @@ -244,7 +244,7 @@ class Adafruit_MQTT { uint8_t connectPacket(uint8_t *packet); uint8_t disconnectPacket(uint8_t *packet); uint16_t publishPacket(uint8_t *packet, uint16_t maxPacketLen, - const char *topic, uint8_t *payload, uint16_t bLen, uint8_t qos); + const char *topic, const uint8_t *payload, uint16_t bLen, uint8_t qos); uint8_t subscribePacket(uint8_t *packet, const char *topic, uint8_t qos); uint8_t unsubscribePacket(uint8_t *packet, const char *topic); uint8_t pingPacket(uint8_t *packet); @@ -262,7 +262,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: