A small footprint MQTT library
Dependents: STM32F746_iothub_client_sample_mqtt FXOS8700CQ_To_Azure_IoT f767zi_mqtt FXOS8700CQ_To_Azure_IoT ... more
Diff: mqtt_codec.c
- Revision:
- 15:ec5a36121959
- Parent:
- 13:3c202001e4ba
- Child:
- 20:a8254fa69b6c
--- a/mqtt_codec.c Fri Feb 10 17:01:07 2017 -0800 +++ b/mqtt_codec.c Fri Feb 24 14:01:11 2017 -0800 @@ -3,6 +3,7 @@ #include <stdlib.h> #include <limits.h> +#include "azure_c_shared_utility/optimize_size.h" #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/buffer_.h" #include "azure_c_shared_utility/strings.h" @@ -129,7 +130,7 @@ int result = 0; if (payloadList == NULL || ctrlPacket == NULL) { - result = __LINE__; + result = __FAILURE__; } else { @@ -141,11 +142,11 @@ size_t topicLen = strlen(payloadList[index]); if (topicLen > USHRT_MAX) { - result = __LINE__; + result = __FAILURE__; } else if (BUFFER_enlarge(ctrlPacket, topicLen + 2) != 0) { - result = __LINE__; + result = __FAILURE__; } else { @@ -167,7 +168,7 @@ int result = 0; if (payloadList == NULL || ctrlPacket == NULL) { - result = __LINE__; + result = __FAILURE__; } else { @@ -179,11 +180,11 @@ size_t topicLen = strlen(payloadList[index].subscribeTopic); if (topicLen > USHRT_MAX) { - result = __LINE__; + result = __FAILURE__; } else if (BUFFER_enlarge(ctrlPacket, topicLen + 2 + 1) != 0) { - result = __LINE__; + result = __FAILURE__; } else { @@ -207,14 +208,14 @@ int result = 0; if (BUFFER_enlarge(ctrlPacket, CONNECT_VARIABLE_HEADER_SIZE) != 0) { - result = __LINE__; + result = __FAILURE__; } else { uint8_t* iterator = BUFFER_u_char(ctrlPacket); if (iterator == NULL) { - result = __LINE__; + result = __FAILURE__; } else { @@ -252,18 +253,18 @@ if (topicLen > USHRT_MAX) { - result = __LINE__; + result = __FAILURE__; } else if (BUFFER_enlarge(ctrlPacket, topicLen + idLen + spaceLen) != 0) { - result = __LINE__; + result = __FAILURE__; } else { uint8_t* iterator = BUFFER_u_char(ctrlPacket); if (iterator == NULL) { - result = __LINE__; + result = __FAILURE__; } else { @@ -293,14 +294,14 @@ int result = 0; if (BUFFER_enlarge(ctrlPacket, 2) != 0) { - result = __LINE__; + result = __FAILURE__; } else { uint8_t* iterator = BUFFER_u_char(ctrlPacket); if (iterator == NULL) { - result = __LINE__; + result = __FAILURE__; } else { @@ -347,7 +348,7 @@ int result; if (ctrlPacket == NULL) { - return __LINE__; + return __FAILURE__; } else { @@ -371,12 +372,12 @@ BUFFER_HANDLE fixedHeader = BUFFER_new(); if (fixedHeader == NULL) { - result = __LINE__; + result = __FAILURE__; } else if (BUFFER_pre_build(fixedHeader, index + 1) != 0) { BUFFER_delete(fixedHeader); - result = __LINE__; + result = __FAILURE__; } else { @@ -397,7 +398,7 @@ int result = 0; if (mqttOptions == NULL || ctrlPacket == NULL) { - result = __LINE__; + result = __FAILURE__; } else { @@ -440,19 +441,19 @@ // Validate the Username & Password if (clientLen > USHRT_MAX) { - result = __LINE__; + result = __FAILURE__; } else if (usernameLen == 0 && passwordLen > 0) { - result = __LINE__; + result = __FAILURE__; } else if ((willMessageLen > 0 && willTopicLen == 0) || (willTopicLen > 0 && willMessageLen == 0)) { - result = __LINE__; + result = __FAILURE__; } else if (BUFFER_enlarge(ctrlPacket, totalLen) != 0) { - result = __LINE__; + result = __FAILURE__; } else { @@ -465,7 +466,7 @@ // TODO: Read on the Will Topic if (willMessageLen > USHRT_MAX || willTopicLen > USHRT_MAX || usernameLen > USHRT_MAX || passwordLen > USHRT_MAX) { - result = __LINE__; + result = __FAILURE__; } else { @@ -534,7 +535,7 @@ int result; if (codecData == NULL) { - result = __LINE__; + result = __FAILURE__; } else { @@ -554,7 +555,7 @@ if (multiplier > 128 * 128 * 128) { - result = __LINE__; + result = __FAILURE__; break; } } while ((encodeByte & NEXT_128_CHUNK) != 0); @@ -1037,14 +1038,14 @@ /* Codes_SRS_MQTT_CODEC_07_031: [If the parameters handle or buffer is NULL then mqtt_codec_bytesReceived shall return a non-zero value.] */ if (codec_Data == NULL) { - result = __LINE__; + result = __FAILURE__; } /* Codes_SRS_MQTT_CODEC_07_031: [If the parameters handle or buffer is NULL then mqtt_codec_bytesReceived shall return a non-zero value.] */ /* Codes_SRS_MQTT_CODEC_07_032: [If the parameters size is zero then mqtt_codec_bytesReceived shall return a non-zero value.] */ else if (buffer == NULL || size == 0) { codec_Data->currPacket = PACKET_TYPE_ERROR; - result = __LINE__; + result = __FAILURE__; } else { @@ -1066,7 +1067,7 @@ { /* Codes_SRS_MQTT_CODEC_07_035: [If any error is encountered then the packet state will be marked as error and mqtt_codec_bytesReceived shall return a non-zero value.] */ codec_Data->currPacket = PACKET_TYPE_ERROR; - result = __LINE__; + result = __FAILURE__; } if (codec_Data->currPacket == PINGRESP_TYPE) { @@ -1088,7 +1089,7 @@ { /* Codes_SRS_MQTT_CODEC_07_035: [If any error is encountered then the packet state will be marked as error and mqtt_codec_bytesReceived shall return a non-zero value.] */ codec_Data->currPacket = PACKET_TYPE_ERROR; - result = __LINE__; + result = __FAILURE__; } else { @@ -1109,7 +1110,7 @@ { /* Codes_SRS_MQTT_CODEC_07_035: [If any error is encountered then the packet state will be marked as error and mqtt_codec_bytesReceived shall return a non-zero value.] */ codec_Data->currPacket = PACKET_TYPE_ERROR; - result = __LINE__; + result = __FAILURE__; } } }