mqtt_msg: avoid uncasting const to mqtt topic and data pointers

This commit is contained in:
David Cermak
2019-05-06 09:37:50 +02:00
parent db71c753aa
commit 60cdb79a67
3 changed files with 10 additions and 10 deletions

View File

@ -113,8 +113,8 @@ static inline int mqtt_get_retain(uint8_t* buffer) { return (buffer[0] & 0x01);
void mqtt_msg_init(mqtt_connection_t* connection, uint8_t* buffer, uint16_t buffer_length);
bool mqtt_header_complete(uint8_t* buffer, uint16_t buffer_length);
uint32_t mqtt_get_total_length(uint8_t* buffer, uint16_t length, int* fixed_size_len);
const char* mqtt_get_publish_topic(uint8_t* buffer, uint32_t* length);
const char* mqtt_get_publish_data(uint8_t* buffer, uint32_t* length);
char* mqtt_get_publish_topic(uint8_t* buffer, uint32_t* length);
char* mqtt_get_publish_data(uint8_t* buffer, uint32_t* length);
uint16_t mqtt_get_id(uint8_t* buffer, uint16_t length);
int mqtt_has_valid_msg_hdr(uint8_t* buffer, uint16_t length);

View File

@ -206,7 +206,7 @@ bool mqtt_header_complete(uint8_t* buffer, uint16_t buffer_length)
return buffer_length >= i;
}
const char* mqtt_get_publish_topic(uint8_t* buffer, uint32_t* length)
char* mqtt_get_publish_topic(uint8_t* buffer, uint32_t* length)
{
int i;
int totlen = 0;
@ -232,10 +232,10 @@ const char* mqtt_get_publish_topic(uint8_t* buffer, uint32_t* length)
return NULL;
*length = topiclen;
return (const char*)(buffer + i);
return (char*)(buffer + i);
}
const char* mqtt_get_publish_data(uint8_t* buffer, uint32_t* length)
char* mqtt_get_publish_data(uint8_t* buffer, uint32_t* length)
{
int i;
int totlen = 0;
@ -278,7 +278,7 @@ const char* mqtt_get_publish_data(uint8_t* buffer, uint32_t* length)
*length = totlen - i;
else
*length = blength - i;
return (const char*)(buffer + i);
return (char*)(buffer + i);
}
uint16_t mqtt_get_id(uint8_t* buffer, uint16_t length)

View File

@ -552,7 +552,7 @@ static esp_err_t deliver_publish(esp_mqtt_client_handle_t client)
size_t msg_total_len = client->mqtt_state.message_length;
size_t msg_topic_len = msg_read_len, msg_data_len = msg_read_len;
size_t msg_data_offset = 0;
const char *msg_topic = NULL, *msg_data = NULL;
char *msg_topic = NULL, *msg_data = NULL;
// get topic
msg_topic = mqtt_get_publish_topic(msg_buf, &msg_topic_len);
@ -577,10 +577,10 @@ post_data_event:
ESP_LOGD(TAG, "Get data len= %d, topic len=%d, total_data: %d offset: %d", msg_data_len, msg_topic_len,
client->event.total_data_len, msg_data_offset);
client->event.event_id = MQTT_EVENT_DATA;
client->event.data = msg_data_len > 0 ? (char *)msg_data : NULL;
client->event.data = msg_data_len > 0 ? msg_data : NULL;
client->event.data_len = msg_data_len;
client->event.current_data_offset = msg_data_offset;
client->event.topic = (char *)msg_topic;
client->event.topic = msg_topic;
client->event.topic_len = msg_topic_len;
esp_mqtt_dispatch_event(client);
@ -589,7 +589,7 @@ post_data_event:
size_t buf_len = client->mqtt_state.in_buffer_length;
esp_transport_handle_t transport = esp_transport_get_payload_transport_handle(client->transport);
msg_data = (const char*)client->mqtt_state.in_buffer;
msg_data = (char*)client->mqtt_state.in_buffer;
msg_topic = NULL;
msg_topic_len = 0;
msg_data_offset += msg_data_len;