diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ebe0212..50dcd593 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ #Copyright (c) Microsoft. All rights reserved. #Licensed under the MIT license. See LICENSE file in the project root for full license information. -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.12.0) if (TARGET umqtt) RETURN() @@ -14,6 +14,10 @@ FILE(READ ${CMAKE_CURRENT_LIST_DIR}/version.txt UMQTT_VERSION) set(GENERIC_LIB_VERSION ${UMQTT_VERSION}) string(SUBSTRING ${UMQTT_VERSION} 0 1 GENERIC_LIB_SOVERSION) +# Set C and C++ standards +set(CMAKE_C_STANDARD 23) +set(CMAKE_CXX_STANDARD 23) + #the following variables are project-wide and can be used with cmake-gui option(run_unittests "set run_unittests to ON to run unittests (default is OFF)" OFF) option(run_e2e_tests "set run_e2e_tests to ON to run e2e tests (default is OFF)" OFF) @@ -114,7 +118,7 @@ set(source_h_files ./inc/azure_umqtt_c/mqtt_message.h ) -#the following "set" statetement exports across the project a global variable called COMMON_INC_FOLDER that expands to whatever needs to included when using COMMON library +#the following "set" statement exports across the project a global variable called COMMON_INC_FOLDER that expands to whatever needs to included when using COMMON library set(MQTT_INC_FOLDER ${CMAKE_CURRENT_LIST_DIR}/inc CACHE INTERNAL "this is what needs to be included if using sharedLib lib" FORCE) set(MQTT_SRC_FOLDER ${CMAKE_CURRENT_LIST_DIR}/src CACHE INTERNAL "this is what needs to be included when doing include sources" FORCE) include_directories(${MQTT_INC_FOLDER} ${SHARED_UTIL_INC_FOLDER} ${UMOCK_C_INC_FOLDER} ${MACRO_UTILS_INC_FOLDER}) diff --git a/inc/azure_umqtt_c/mqttconst.h b/inc/azure_umqtt_c/mqttconst.h index ce4e761a..c7ad3ebe 100644 --- a/inc/azure_umqtt_c/mqttconst.h +++ b/inc/azure_umqtt_c/mqttconst.h @@ -16,35 +16,66 @@ extern "C" { #include #endif /* __cplusplus */ +// Define CONTROL_PACKET_TYPE without numeric constants #define CONTROL_PACKET_TYPE_VALUES \ - CONNECT_TYPE, 0x10, \ - CONNACK_TYPE, 0x20, \ - PUBLISH_TYPE, 0x30, \ - PUBACK_TYPE, 0x40, \ - PUBREC_TYPE, 0x50, \ - PUBREL_TYPE, 0x60, \ - PUBCOMP_TYPE, 0x70, \ - SUBSCRIBE_TYPE, 0x80, \ - SUBACK_TYPE, 0x90, \ - UNSUBSCRIBE_TYPE, 0xA0, \ - UNSUBACK_TYPE, 0xB0, \ - PINGREQ_TYPE, 0xC0, \ - PINGRESP_TYPE, 0xD0, \ - DISCONNECT_TYPE, 0xE0, \ - PACKET_TYPE_ERROR, 0xE1, /* 0xE1 was assigned because ENUM_2 needs it */ \ - UNKNOWN_TYPE, 0xE2, /* 0xE2 was assigned because ENUM_2 needs it */ \ - PACKET_INVALID1_TYPE, 0x00, \ - PACKET_INVALID2_TYPE, 0xF0 - -MU_DEFINE_ENUM_2(CONTROL_PACKET_TYPE, CONTROL_PACKET_TYPE_VALUES) - + CONNECT_TYPE, \ + CONNACK_TYPE, \ + PUBLISH_TYPE, \ + PUBACK_TYPE, \ + PUBREC_TYPE, \ + PUBREL_TYPE, \ + PUBCOMP_TYPE, \ + SUBSCRIBE_TYPE, \ + SUBACK_TYPE, \ + UNSUBSCRIBE_TYPE, \ + UNSUBACK_TYPE, \ + PINGREQ_TYPE, \ + PINGRESP_TYPE, \ + DISCONNECT_TYPE, \ + PACKET_TYPE_ERROR, \ + UNKNOWN_TYPE, \ + PACKET_INVALID1_TYPE, \ + PACKET_INVALID2_TYPE + +MU_DEFINE_ENUM(CONTROL_PACKET_TYPE, CONTROL_PACKET_TYPE_VALUES) + +// Define QOS_VALUE without numeric constants #define QOS_VALUE_VALUES \ - DELIVER_AT_MOST_ONCE, 0x00, \ - DELIVER_AT_LEAST_ONCE, 0x01, \ - DELIVER_EXACTLY_ONCE, 0x02, \ - DELIVER_FAILURE, 0x80 - -MU_DEFINE_ENUM_2(QOS_VALUE, QOS_VALUE_VALUES) + DELIVER_AT_MOST_ONCE, \ + DELIVER_AT_LEAST_ONCE, \ + DELIVER_EXACTLY_ONCE, \ + DELIVER_FAILURE + +MU_DEFINE_ENUM(QOS_VALUE, QOS_VALUE_VALUES) + +// Map enum values to numeric constants +static const int CONTROL_PACKET_TYPE_NUMERIC_VALUES[] = { + [CONNECT_TYPE] = 0x10, + [CONNACK_TYPE] = 0x20, + [PUBLISH_TYPE] = 0x30, + [PUBACK_TYPE] = 0x40, + [PUBREC_TYPE] = 0x50, + [PUBREL_TYPE] = 0x60, + [PUBCOMP_TYPE] = 0x70, + [SUBSCRIBE_TYPE] = 0x80, + [SUBACK_TYPE] = 0x90, + [UNSUBSCRIBE_TYPE] = 0xA0, + [UNSUBACK_TYPE] = 0xB0, + [PINGREQ_TYPE] = 0xC0, + [PINGRESP_TYPE] = 0xD0, + [DISCONNECT_TYPE] = 0xE0, + [PACKET_TYPE_ERROR] = 0xE1, + [UNKNOWN_TYPE] = 0xE2, + [PACKET_INVALID1_TYPE] = 0x00, + [PACKET_INVALID2_TYPE] = 0xF0 +}; + +static const int QOS_VALUE_NUMERIC_VALUES[] = { + [DELIVER_AT_MOST_ONCE] = 0x00, + [DELIVER_AT_LEAST_ONCE] = 0x01, + [DELIVER_EXACTLY_ONCE] = 0x02, + [DELIVER_FAILURE] = 0x80 +}; typedef struct APP_PAYLOAD_TAG { diff --git a/src/mqtt_client.c b/src/mqtt_client.c index 199735bb..a1b6585a 100644 --- a/src/mqtt_client.c +++ b/src/mqtt_client.c @@ -33,7 +33,7 @@ static const char* const TRUE_CONST = "true"; static const char* const FALSE_CONST = "false"; -MU_DEFINE_ENUM_STRINGS_2(QOS_VALUE, QOS_VALUE_VALUES); +MU_DEFINE_ENUM_STRINGS(QOS_VALUE, QOS_VALUE_VALUES); #define MQTT_STATUS_INITIAL_STATUS 0x0000 #define MQTT_STATUS_CLIENT_CONNECTED 0x0001 @@ -710,7 +710,7 @@ static void ProcessPublishMessage(MQTT_CLIENT* mqtt_client, uint8_t* initialPos, if (is_trace_enabled(mqtt_client)) { trace_log = STRING_construct_sprintf("PUBLISH | IS_DUP: %s | RETAIN: %d | QOS: %s | TOPIC_NAME: %s", isDuplicateMsg ? TRUE_CONST : FALSE_CONST, - isRetainMsg ? 1 : 0, MU_ENUM_TO_STRING_2(QOS_VALUE, qosValue), topicName); + isRetainMsg ? 1 : 0, MU_ENUM_TO_STRING(QOS_VALUE, qosValue), topicName); } #endif uint16_t packetId = 0; diff --git a/src/mqtt_codec.c b/src/mqtt_codec.c index 56e0a101..22509824 100644 --- a/src/mqtt_codec.c +++ b/src/mqtt_codec.c @@ -1118,7 +1118,7 @@ int mqtt_codec_bytesReceived(MQTTCODEC_HANDLE handle, const unsigned char* buffe break; case PUBLISH_TYPE: - case CONTROL_PACKET_TYPE_INVALID: + // case CONTROL_PACKET_TYPE_INVALID: case PACKET_TYPE_ERROR: case UNKNOWN_TYPE: break; diff --git a/tests/mqtt_client_ut/CMakeLists.txt b/tests/mqtt_client_ut/CMakeLists.txt index 0f7de8d8..016c9364 100644 --- a/tests/mqtt_client_ut/CMakeLists.txt +++ b/tests/mqtt_client_ut/CMakeLists.txt @@ -1,7 +1,7 @@ #Copyright (c) Microsoft. All rights reserved. #Licensed under the MIT license. See LICENSE file in the project root for full license information. -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.12.0) set(theseTestsName mqtt_client_ut) diff --git a/tests/mqtt_client_ut/mqtt_client_ut.c b/tests/mqtt_client_ut/mqtt_client_ut.c index 6aea76b6..eb8dea82 100644 --- a/tests/mqtt_client_ut/mqtt_client_ut.c +++ b/tests/mqtt_client_ut/mqtt_client_ut.c @@ -72,8 +72,8 @@ extern "C" } #endif -TEST_DEFINE_ENUM_2_TYPE(QOS_VALUE, QOS_VALUE_VALUES); -IMPLEMENT_UMOCK_C_ENUM_2_TYPE(QOS_VALUE, QOS_VALUE_VALUES); +TEST_DEFINE_ENUM_TYPE(QOS_VALUE, QOS_VALUE_VALUES); +IMPLEMENT_UMOCK_C_ENUM_TYPE(QOS_VALUE, QOS_VALUE_VALUES); static const char* TEST_USERNAME = "testuser"; static const char* TEST_PASSWORD = "testpassword"; diff --git a/tests/mqtt_codec_ut/mqtt_codec_ut.c b/tests/mqtt_codec_ut/mqtt_codec_ut.c index 1e6e06e4..77545bd7 100644 --- a/tests/mqtt_codec_ut/mqtt_codec_ut.c +++ b/tests/mqtt_codec_ut/mqtt_codec_ut.c @@ -121,9 +121,9 @@ STRING_HANDLE STRING_construct_sprintf(const char* format, ...) } #endif -MU_DEFINE_ENUM_STRINGS_2(CONTROL_PACKET_TYPE, CONTROL_PACKET_TYPE_VALUES); -TEST_DEFINE_ENUM_2_TYPE(CONTROL_PACKET_TYPE, CONTROL_PACKET_TYPE_VALUES); -IMPLEMENT_UMOCK_C_ENUM_2_TYPE(CONTROL_PACKET_TYPE, CONTROL_PACKET_TYPE_VALUES); +MU_DEFINE_ENUM_STRINGS(CONTROL_PACKET_TYPE, CONTROL_PACKET_TYPE_VALUES); +TEST_DEFINE_ENUM_TYPE(CONTROL_PACKET_TYPE, CONTROL_PACKET_TYPE_VALUES); +IMPLEMENT_UMOCK_C_ENUM_TYPE(CONTROL_PACKET_TYPE, CONTROL_PACKET_TYPE_VALUES); static void SetupMqttLibOptions(MQTT_CLIENT_OPTIONS* options, const char* clientId, const char* willMsg, diff --git a/tests/mqtt_message_ut/mqtt_message_ut.c b/tests/mqtt_message_ut/mqtt_message_ut.c index 75b5234f..79a3e240 100644 --- a/tests/mqtt_message_ut/mqtt_message_ut.c +++ b/tests/mqtt_message_ut/mqtt_message_ut.c @@ -88,9 +88,9 @@ typedef struct TEST_COMPLETE_DATA_INSTANCE_TAG size_t Length; } TEST_COMPLETE_DATA_INSTANCE; -MU_DEFINE_ENUM_STRINGS_2(QOS_VALUE, QOS_VALUE_VALUES); -TEST_DEFINE_ENUM_2_TYPE(QOS_VALUE, QOS_VALUE_VALUES); -IMPLEMENT_UMOCK_C_ENUM_2_TYPE(QOS_VALUE, QOS_VALUE_VALUES); +MU_DEFINE_ENUM_STRINGS(QOS_VALUE, QOS_VALUE_VALUES); +TEST_DEFINE_ENUM_TYPE(QOS_VALUE, QOS_VALUE_VALUES); +IMPLEMENT_UMOCK_C_ENUM_TYPE(QOS_VALUE, QOS_VALUE_VALUES); TEST_MUTEX_HANDLE test_serialize_mutex;