A small footprint MQTT library
Dependents: STM32F746_iothub_client_sample_mqtt FXOS8700CQ_To_Azure_IoT f767zi_mqtt FXOS8700CQ_To_Azure_IoT ... more
Diff: mqtt_client.c
- Revision:
- 28:35eea447689a
- Parent:
- 27:a2eb9cb1e731
- Child:
- 29:7bb0aae34648
--- a/mqtt_client.c Fri May 04 13:25:24 2018 -0700 +++ b/mqtt_client.c Mon Jun 11 15:40:18 2018 -0700 @@ -208,6 +208,7 @@ } } +#ifndef NO_LOGGING static const char* retrievePacketType(CONTROL_PACKET_TYPE packet) { switch (packet&CONNECT_PACKET_MASK) @@ -231,6 +232,7 @@ return "UNKNOWN"; } } +#endif // NO_LOGGING static void getLogTime(char* timeResult, size_t len) { @@ -602,7 +604,10 @@ /*Codes_SRS_MQTT_CLIENT_07_028: [If the actionResult parameter is of type CONNECT_ACK then the msgInfo value shall be a CONNECT_ACK structure.]*/ CONNECT_ACK connack = { 0 }; connack.isSessionPresent = (byteutil_readByte(&iterator) == 0x1) ? true : false; - connack.returnCode = byteutil_readByte(&iterator); + uint8_t rc = byteutil_readByte(&iterator); + connack.returnCode = + (rc < ((uint8_t)CONN_REFUSED_UNKNOWN)) ? + (CONNECT_RETURN_CODE)rc : CONN_REFUSED_UNKNOWN; if (mqtt_client->logTrace) { @@ -635,7 +640,7 @@ if (mqtt_client->logTrace) { - trace_log = STRING_construct_sprintf("PUBLISH | IS_DUP: %s | RETAIN: %d | QOS: %s", isDuplicateMsg ? TRUE_CONST : FALSE_CONST, + trace_log = STRING_construct_sprintf("PUBLISH | IS_DUP: %s | RETAIN: %d | QOS: %s", isDuplicateMsg ? TRUE_CONST : FALSE_CONST, isRetainMsg ? 1 : 0, ENUM_TO_STRING(QOS_VALUE, qosValue) ); } @@ -812,7 +817,10 @@ { while (remainLen > 0) { - suback.qosReturn[suback.qosCount++] = byteutil_readByte(&iterator); + uint8_t qosRet = byteutil_readByte(&iterator); + suback.qosReturn[suback.qosCount++] = + (qosRet <= ((uint8_t)DELIVER_EXACTLY_ONCE)) ? + (QOS_VALUE)qosRet : DELIVER_FAILURE; remainLen--; if (mqtt_client->logTrace) { @@ -864,7 +872,7 @@ log_incoming_trace(mqtt_client, trace_log); STRING_delete(trace_log); } - // Forward ping response to operation callback + // Forward ping response to operation callback if (mqtt_client->fnOperationCallback) { mqtt_client->fnOperationCallback(mqtt_client, MQTT_CLIENT_ON_PING_RESPONSE, NULL, mqtt_client->ctx);