Merge branch 'bugfix/size_t_for_all_lengths' into 'master'

Use size_t for all lengths

See merge request espressif/esp-mqtt!79
This commit is contained in:
David Čermák
2020-10-12 18:16:29 +08:00
3 changed files with 21 additions and 21 deletions

View File

@ -63,9 +63,9 @@ enum mqtt_message_type {
typedef struct mqtt_message {
uint8_t *data;
uint32_t length;
uint32_t fragmented_msg_total_length; /*!< total len of fragmented messages (zero for all other messages) */
uint32_t fragmented_msg_data_offset; /*!< data offset of fragmented messages (zero for all other messages) */
size_t length;
size_t fragmented_msg_total_length; /*!< total len of fragmented messages (zero for all other messages) */
size_t fragmented_msg_data_offset; /*!< data offset of fragmented messages (zero for all other messages) */
} mqtt_message_t;
typedef struct mqtt_connection {
@ -73,7 +73,7 @@ typedef struct mqtt_connection {
uint16_t message_id;
uint8_t *buffer;
uint32_t buffer_length;
size_t buffer_length;
} mqtt_connection_t;
@ -122,13 +122,13 @@ static inline int mqtt_get_retain(const uint8_t *buffer)
return (buffer[0] & 0x01);
}
void mqtt_msg_init(mqtt_connection_t *connection, uint8_t *buffer, uint32_t buffer_length);
bool mqtt_header_complete(uint8_t *buffer, uint32_t buffer_length);
uint32_t mqtt_get_total_length(const uint8_t *buffer, uint32_t length, int *fixed_size_len);
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, uint32_t length);
int mqtt_has_valid_msg_hdr(uint8_t *buffer, uint32_t length);
void mqtt_msg_init(mqtt_connection_t *connection, uint8_t *buffer, size_t buffer_length);
bool mqtt_header_complete(uint8_t *buffer, size_t buffer_length);
size_t mqtt_get_total_length(const uint8_t *buffer, size_t length, int *fixed_size_len);
char *mqtt_get_publish_topic(uint8_t *buffer, size_t *length);
char *mqtt_get_publish_data(uint8_t *buffer, size_t *length);
uint16_t mqtt_get_id(uint8_t *buffer, size_t length);
int mqtt_has_valid_msg_hdr(uint8_t *buffer, size_t length);
mqtt_message_t *mqtt_msg_connect(mqtt_connection_t *connection, mqtt_connect_info_t *info);
mqtt_message_t *mqtt_msg_publish(mqtt_connection_t *connection, const char *topic, const char *data, int data_length, int qos, int retain, uint16_t *message_id);

View File

@ -133,17 +133,17 @@ static mqtt_message_t *fini_message(mqtt_connection_t *connection, int type, int
return &connection->message;
}
void mqtt_msg_init(mqtt_connection_t *connection, uint8_t *buffer, uint32_t buffer_length)
void mqtt_msg_init(mqtt_connection_t *connection, uint8_t *buffer, size_t buffer_length)
{
memset(connection, 0, sizeof(mqtt_connection_t));
connection->buffer = buffer;
connection->buffer_length = buffer_length;
}
uint32_t mqtt_get_total_length(const uint8_t *buffer, uint32_t length, int *fixed_size_len)
size_t mqtt_get_total_length(const uint8_t *buffer, size_t length, int *fixed_size_len)
{
int i;
uint32_t totlen = 0;
size_t totlen = 0;
for (i = 1; i < length; ++i) {
totlen += (buffer[i] & 0x7f) << (7 * (i - 1));
@ -160,7 +160,7 @@ uint32_t mqtt_get_total_length(const uint8_t *buffer, uint32_t length, int *fixe
return totlen;
}
bool mqtt_header_complete(uint8_t *buffer, uint32_t buffer_length)
bool mqtt_header_complete(uint8_t *buffer, size_t buffer_length)
{
uint16_t i;
uint16_t topiclen;
@ -191,7 +191,7 @@ bool mqtt_header_complete(uint8_t *buffer, uint32_t buffer_length)
return buffer_length >= i;
}
char *mqtt_get_publish_topic(uint8_t *buffer, uint32_t *length)
char *mqtt_get_publish_topic(uint8_t *buffer, size_t *length)
{
int i;
int totlen = 0;
@ -220,7 +220,7 @@ char *mqtt_get_publish_topic(uint8_t *buffer, uint32_t *length)
return (char *)(buffer + i);
}
char *mqtt_get_publish_data(uint8_t *buffer, uint32_t *length)
char *mqtt_get_publish_data(uint8_t *buffer, size_t *length)
{
int i;
int totlen = 0;
@ -268,7 +268,7 @@ char *mqtt_get_publish_data(uint8_t *buffer, uint32_t *length)
return (char *)(buffer + i);
}
uint16_t mqtt_get_id(uint8_t *buffer, uint32_t length)
uint16_t mqtt_get_id(uint8_t *buffer, size_t length)
{
if (length < 1) {
return 0;
@ -558,7 +558,7 @@ mqtt_message_t *mqtt_msg_disconnect(mqtt_connection_t *connection)
* check flags: [MQTT-2.2.2-1], [MQTT-2.2.2-2]
* returns 0 if flags are invalid, otherwise returns 1
*/
int mqtt_has_valid_msg_hdr(uint8_t *buffer, uint32_t length)
int mqtt_has_valid_msg_hdr(uint8_t *buffer, size_t length)
{
int qos, dup;

View File

@ -43,8 +43,8 @@ typedef struct mqtt_state
uint8_t *out_buffer;
int in_buffer_length;
int out_buffer_length;
uint32_t message_length;
uint32_t in_buffer_read_len;
size_t message_length;
size_t in_buffer_read_len;
mqtt_message_t *outbound_message;
mqtt_connection_t mqtt_connection;
uint16_t pending_msg_id;