From 22ccf993f14bf875a8b084bbf11fd6141d720d30 Mon Sep 17 00:00:00 2001 From: CIPop Date: Tue, 25 Jul 2023 21:07:01 +0000 Subject: [PATCH 1/3] Renaming V5 reason code public API to avoid collisions. Disabling deprecation warnings for tests to avoid build warnings. --- MQTTClient-C/test/CMakeLists.txt | 4 + MQTTClient/test/CMakeLists.txt | 5 + MQTTPacket/samples/v5log.c | 162 ++++++++++++++-------------- MQTTPacket/samples/v5ping.c | 2 +- MQTTPacket/samples/v5ping_nb.c | 2 +- MQTTPacket/samples/v5qos0pub.c | 2 +- MQTTPacket/src/V5/MQTTReasonCodes.h | 90 ++++++++-------- MQTTPacket/test/CMakeLists.txt | 16 +++ MQTTPacket/test/test2.c | 6 +- 9 files changed, 157 insertions(+), 132 deletions(-) diff --git a/MQTTClient-C/test/CMakeLists.txt b/MQTTClient-C/test/CMakeLists.txt index 9df121af..167ea186 100644 --- a/MQTTClient-C/test/CMakeLists.txt +++ b/MQTTClient-C/test/CMakeLists.txt @@ -18,3 +18,7 @@ ADD_TEST( NAME testc1 COMMAND "testc1" "--host" ${MQTT_TEST_BROKER_HOST} ) + +# Disabling deprecation warnings: +# warning: ‘ftime’ is deprecated [-Wdeprecated-declarations] +target_compile_options(testc1 PRIVATE -Wno-deprecated-declarations) diff --git a/MQTTClient/test/CMakeLists.txt b/MQTTClient/test/CMakeLists.txt index 6a485d81..21f65591 100644 --- a/MQTTClient/test/CMakeLists.txt +++ b/MQTTClient/test/CMakeLists.txt @@ -14,7 +14,12 @@ target_compile_definitions(testcpp1 PRIVATE MQTTCLIENT_QOS1=1 MQTTCLIENT_QOS2=1) target_include_directories(testcpp1 PRIVATE "../src" "../src/linux") target_link_libraries(testcpp1 MQTTPacketClient MQTTPacketServer) +# Disabling deprecation warnings: +# warning: ‘ftime’ is deprecated [-Wdeprecated-declarations] +target_compile_options(testcpp1 PRIVATE -Wno-deprecated-declarations) + ADD_TEST( NAME testcpp1 COMMAND "testcpp1" "--host" ${MQTT_TEST_BROKER_HOST} ) + diff --git a/MQTTPacket/samples/v5log.c b/MQTTPacket/samples/v5log.c index a204dc90..326623ae 100644 --- a/MQTTPacket/samples/v5log.c +++ b/MQTTPacket/samples/v5log.c @@ -142,87 +142,87 @@ const char* v5reasoncode_to_string(enum ReasonCodes reasoncode) { switch (reasoncode) { - case SUCCESS: - return "SUCCESS"; - case NO_MATCHING_SUBSCRIBERS: - return "NO_MATCHING_SUBSCRIBERS"; - case NO_SUBSCRIPTION_FOUND: - return "NO_SUBSCRIPTION_FOUND"; - case CONTINUE_AUTHENTICATION: - return "CONTINUE_AUTHENTICATION"; - case RE_AUTHENTICATE: - return "RE_AUTHENTICATE"; - case UNSPECIFIED_ERROR: - return "UNSPECIFIED_ERROR"; - case MALFORMED_PACKET: - return "MALFORMED_PACKET"; - case PROTOCOL_ERROR: - return "PROTOCOL_ERROR"; - case IMPLEMENTATION_SPECIFIC_ERROR: - return "IMPLEMENTATION_SPECIFIC_ERROR"; - case UNSUPPORTED_PROTOCOL_VERSION: - return "UNSUPPORTED_PROTOCOL_VERSION"; - case CLIENT_IDENTIFIER_NOT_VALID: - return "CLIENT_IDENTIFIER_NOT_VALID"; - case BAD_USER_NAME_OR_PASSWORD: - return "BAD_USER_NAME_OR_PASSWORD"; - case NOT_AUTHORIZED: - return "NOT_AUTHORIZED"; - case SERVER_UNAVAILABLE: - return "SERVER_UNAVAILABLE"; - case SERVER_BUSY: - return "SERVER_BUSY"; - case BANNED: - return "BANNED"; - case SERVER_SHUTTING_DOWN: - return "SERVER_SHUTTING_DOWN"; - case BAD_AUTHENTICATION_METHOD: - return "BAD_AUTHENTICATION_METHOD"; - case KEEP_ALIVE_TIMEOUT: - return "KEEP_ALIVE_TIMEOUT"; - case SESSION_TAKEN_OVER: - return "SESSION_TAKEN_OVER"; - case TOPIC_FILTER_INVALID: - return "TOPIC_FILTER_INVALID"; - case TOPIC_NAME_INVALID: - return "TOPIC_NAME_INVALID"; - case PACKET_IDENTIFIER_IN_USE: - return "PACKET_IDENTIFIER_IN_USE"; - case PACKET_IDENTIFIER_NOT_FOUND: - return "PACKET_IDENTIFIER_NOT_FOUND"; - case RECEIVE_MAXIMUM_EXCEEDED: - return "RECEIVE_MAXIMUM_EXCEEDED"; - case TOPIC_ALIAS_INVALID: - return "TOPIC_ALIAS_INVALID"; - case PACKET_TOO_LARGE: - return "PACKET_TOO_LARGE"; - case MESSAGE_RATE_TOO_HIGH: - return "MESSAGE_RATE_TOO_HIGH"; - case QUOTA_EXCEEDED: - return "QUOTA_EXCEEDED"; - case ADMINISTRATIVE_ACTION: - return "ADMINISTRATIVE_ACTION"; - case PAYLOAD_FORMAT_INVALID: - return "PAYLOAD_FORMAT_INVALID"; - case RETAIN_NOT_SUPPORTED: - return "RETAIN_NOT_SUPPORTED"; - case QOS_NOT_SUPPORTED: - return "QOS_NOT_SUPPORTED"; - case USE_ANOTHER_SERVER: - return "USE_ANOTHER_SERVER"; - case SERVER_MOVED: - return "SERVER_MOVED"; - case SHARED_SUBSCRIPTION_NOT_SUPPORTED: - return "SHARED_SUBSCRIPTION_NOT_SUPPORTED"; - case CONNECTION_RATE_EXCEEDED: - return "CONNECTION_RATE_EXCEEDED"; - case MAXIMUM_CONNECT_TIME: - return "MAXIMUM_CONNECT_TIME"; - case SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED: - return "SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED"; - case WILDCARD_SUBSCRIPTION_NOT_SUPPORTED: - return "WILDCARD_SUBSCRIPTION_NOT_SUPPORTED"; + case MQTTV5_SUCCESS: + return "MQTTV5_SUCCESS"; + case MQTTV5_NO_MATCHING_SUBSCRIBERS: + return "MQTTV5_NO_MATCHING_SUBSCRIBERS"; + case MQTTV5_NO_SUBSCRIPTION_FOUND: + return "MQTTV5_NO_SUBSCRIPTION_FOUND"; + case MQTTV5_CONTINUE_AUTHENTICATION: + return "MQTTV5_CONTINUE_AUTHENTICATION"; + case MQTTV5_RE_AUTHENTICATE: + return "MQTTV5_RE_AUTHENTICATE"; + case MQTTV5_UNSPECIFIED_ERROR: + return "MQTTV5_UNSPECIFIED_ERROR"; + case MQTTV5_MALFORMED_PACKET: + return "MQTTV5_MALFORMED_PACKET"; + case MQTTV5_PROTOCOL_ERROR: + return "MQTTV5_PROTOCOL_ERROR"; + case MQTTV5_IMPLEMENTATION_SPECIFIC_ERROR: + return "MQTTV5_IMPLEMENTATION_SPECIFIC_ERROR"; + case MQTTV5_UNSUPPORTED_PROTOCOL_VERSION: + return "MQTTV5_UNSUPPORTED_PROTOCOL_VERSION"; + case MQTTV5_CLIENT_IDENTIFIER_NOT_VALID: + return "MQTTV5_CLIENT_IDENTIFIER_NOT_VALID"; + case MQTTV5_BAD_USER_NAME_OR_PASSWORD: + return "MQTTV5_BAD_USER_NAME_OR_PASSWORD"; + case MQTTV5_NOT_AUTHORIZED: + return "MQTTV5_NOT_AUTHORIZED"; + case MQTTV5_SERVER_UNAVAILABLE: + return "MQTTV5_SERVER_UNAVAILABLE"; + case MQTTV5_SERVER_BUSY: + return "MQTTV5_SERVER_BUSY"; + case MQTTV5_BANNED: + return "MQTTV5_BANNED"; + case MQTTV5_SERVER_SHUTTING_DOWN: + return "MQTTV5_SERVER_SHUTTING_DOWN"; + case MQTTV5_BAD_AUTHENTICATION_METHOD: + return "MQTTV5_BAD_AUTHENTICATION_METHOD"; + case MQTTV5_KEEP_ALIVE_TIMEOUT: + return "MQTTV5_KEEP_ALIVE_TIMEOUT"; + case MQTTV5_SESSION_TAKEN_OVER: + return "MQTTV5_SESSION_TAKEN_OVER"; + case MQTTV5_TOPIC_FILTER_INVALID: + return "MQTTV5_TOPIC_FILTER_INVALID"; + case MQTTV5_TOPIC_NAME_INVALID: + return "MQTTV5_TOPIC_NAME_INVALID"; + case MQTTV5_PACKET_IDENTIFIER_IN_USE: + return "MQTTV5_PACKET_IDENTIFIER_IN_USE"; + case MQTTV5_PACKET_IDENTIFIER_NOT_FOUND: + return "MQTTV5_PACKET_IDENTIFIER_NOT_FOUND"; + case MQTTV5_RECEIVE_MAXIMUM_EXCEEDED: + return "MQTTV5_RECEIVE_MAXIMUM_EXCEEDED"; + case MQTTV5_TOPIC_ALIAS_INVALID: + return "MQTTV5_TOPIC_ALIAS_INVALID"; + case MQTTV5_PACKET_TOO_LARGE: + return "MQTTV5_PACKET_TOO_LARGE"; + case MQTTV5_MESSAGE_RATE_TOO_HIGH: + return "MQTTV5_MESSAGE_RATE_TOO_HIGH"; + case MQTTV5_QUOTA_EXCEEDED: + return "MQTTV5_QUOTA_EXCEEDED"; + case MQTTV5_ADMINISTRATIVE_ACTION: + return "MQTTV5_ADMINISTRATIVE_ACTION"; + case MQTTV5_PAYLOAD_FORMAT_INVALID: + return "MQTTV5_PAYLOAD_FORMAT_INVALID"; + case MQTTV5_RETAIN_NOT_SUPPORTED: + return "MQTTV5_RETAIN_NOT_SUPPORTED"; + case MQTTV5_QOS_NOT_SUPPORTED: + return "MQTTV5_QOS_NOT_SUPPORTED"; + case MQTTV5_USE_ANOTHER_SERVER: + return "MQTTV5_USE_ANOTHER_SERVER"; + case MQTTV5_SERVER_MOVED: + return "MQTTV5_SERVER_MOVED"; + case MQTTV5_SHARED_SUBSCRIPTION_NOT_SUPPORTED: + return "MQTTV5_SHARED_SUBSCRIPTION_NOT_SUPPORTED"; + case MQTTV5_CONNECTION_RATE_EXCEEDED: + return "MQTTV5_CONNECTION_RATE_EXCEEDED"; + case MQTTV5_MAXIMUM_CONNECT_TIME: + return "MQTTV5_MAXIMUM_CONNECT_TIME"; + case MQTTV5_SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED: + return "MQTTV5_SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED"; + case MQTTV5_WILDCARD_SUBSCRIPTION_NOT_SUPPORTED: + return "MQTTV5_WILDCARD_SUBSCRIPTION_NOT_SUPPORTED"; default: - return "UNKNOWN"; + return "MQTTV5_UNKNOWN"; } } diff --git a/MQTTPacket/samples/v5ping.c b/MQTTPacket/samples/v5ping.c index a26a07c8..f8ec17db 100644 --- a/MQTTPacket/samples/v5ping.c +++ b/MQTTPacket/samples/v5ping.c @@ -147,7 +147,7 @@ int main(int argc, char *argv[]) printf("disconnecting\n"); MQTTProperties disconn_properties = MQTTProperties_initializer; - len = MQTTV5Serialize_disconnect(buf, buflen, NORMAL_DISCONNECTION, &disconn_properties); + len = MQTTV5Serialize_disconnect(buf, buflen, MQTTV5_NORMAL_DISCONNECTION, &disconn_properties); rc = transport_sendPacketBuffer(mysock, buf, len); diff --git a/MQTTPacket/samples/v5ping_nb.c b/MQTTPacket/samples/v5ping_nb.c index 092f2c43..e2d43578 100644 --- a/MQTTPacket/samples/v5ping_nb.c +++ b/MQTTPacket/samples/v5ping_nb.c @@ -164,7 +164,7 @@ int main(int argc, char *argv[]) printf("disconnecting\n"); MQTTProperties disconn_properties = MQTTProperties_initializer; - len = MQTTV5Serialize_disconnect(buf, buflen, NORMAL_DISCONNECTION, &disconn_properties); + len = MQTTV5Serialize_disconnect(buf, buflen, MQTTV5_NORMAL_DISCONNECTION, &disconn_properties); rc = transport_sendPacketBuffer(mysock, buf, len); diff --git a/MQTTPacket/samples/v5qos0pub.c b/MQTTPacket/samples/v5qos0pub.c index bd25664a..4404c951 100644 --- a/MQTTPacket/samples/v5qos0pub.c +++ b/MQTTPacket/samples/v5qos0pub.c @@ -80,7 +80,7 @@ int main(int argc, char *argv[]) len += MQTTV5Serialize_publish((unsigned char *)(buf + len), buflen - len, 0, 1, 0, 123, topicString, &pub_properties, (unsigned char *)payload, payloadlen); MQTTProperties disconnect_properties = MQTTProperties_initializer; - len += MQTTV5Serialize_disconnect((unsigned char *)(buf + len), buflen - len, NORMAL_DISCONNECTION, &disconnect_properties); + len += MQTTV5Serialize_disconnect((unsigned char *)(buf + len), buflen - len, MQTTV5_NORMAL_DISCONNECTION, &disconnect_properties); rc = transport_sendPacketBuffer(mysock, (unsigned char*)buf, len); if (rc == len) diff --git a/MQTTPacket/src/V5/MQTTReasonCodes.h b/MQTTPacket/src/V5/MQTTReasonCodes.h index 02a090a5..070c978f 100644 --- a/MQTTPacket/src/V5/MQTTReasonCodes.h +++ b/MQTTPacket/src/V5/MQTTReasonCodes.h @@ -15,49 +15,49 @@ *******************************************************************************/ enum ReasonCodes { - SUCCESS = 0, - NORMAL_DISCONNECTION = 0, - GRANTED_QOS_0 = 0, - GRANTED_QOS_1 = 1, - GRANTED_QOS_2 = 2, - DISCONNECT_WITH_WILL_MESSAGE = 4, - NO_MATCHING_SUBSCRIBERS = 16, - NO_SUBSCRIPTION_FOUND = 17, - CONTINUE_AUTHENTICATION = 24, - RE_AUTHENTICATE = 25, - UNSPECIFIED_ERROR = 128, - MALFORMED_PACKET = 129, - PROTOCOL_ERROR = 130, - IMPLEMENTATION_SPECIFIC_ERROR = 131, - UNSUPPORTED_PROTOCOL_VERSION = 132, - CLIENT_IDENTIFIER_NOT_VALID = 133, - BAD_USER_NAME_OR_PASSWORD = 134, - NOT_AUTHORIZED = 135, - SERVER_UNAVAILABLE = 136, - SERVER_BUSY = 137, - BANNED = 138, - SERVER_SHUTTING_DOWN = 139, - BAD_AUTHENTICATION_METHOD = 140, - KEEP_ALIVE_TIMEOUT = 141, - SESSION_TAKEN_OVER = 142, - TOPIC_FILTER_INVALID = 143, - TOPIC_NAME_INVALID = 144, - PACKET_IDENTIFIER_IN_USE = 145, - PACKET_IDENTIFIER_NOT_FOUND = 146, - RECEIVE_MAXIMUM_EXCEEDED = 147, - TOPIC_ALIAS_INVALID = 148, - PACKET_TOO_LARGE = 149, - MESSAGE_RATE_TOO_HIGH = 150, - QUOTA_EXCEEDED = 151, - ADMINISTRATIVE_ACTION = 152, - PAYLOAD_FORMAT_INVALID = 153, - RETAIN_NOT_SUPPORTED = 154, - QOS_NOT_SUPPORTED = 155, - USE_ANOTHER_SERVER = 156, - SERVER_MOVED = 157, - SHARED_SUBSCRIPTION_NOT_SUPPORTED = 158, - CONNECTION_RATE_EXCEEDED = 159, - MAXIMUM_CONNECT_TIME = 160, - SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED = 161, - WILDCARD_SUBSCRIPTION_NOT_SUPPORTED = 162 + MQTTV5_SUCCESS = 0, + MQTTV5_NORMAL_DISCONNECTION = 0, + MQTTV5_GRANTED_QOS_0 = 0, + MQTTV5_GRANTED_QOS_1 = 1, + MQTTV5_GRANTED_QOS_2 = 2, + MQTTV5_DISCONNECT_WITH_WILL_MESSAGE = 4, + MQTTV5_NO_MATCHING_SUBSCRIBERS = 16, + MQTTV5_NO_SUBSCRIPTION_FOUND = 17, + MQTTV5_CONTINUE_AUTHENTICATION = 24, + MQTTV5_RE_AUTHENTICATE = 25, + MQTTV5_UNSPECIFIED_ERROR = 128, + MQTTV5_MALFORMED_PACKET = 129, + MQTTV5_PROTOCOL_ERROR = 130, + MQTTV5_IMPLEMENTATION_SPECIFIC_ERROR = 131, + MQTTV5_UNSUPPORTED_PROTOCOL_VERSION = 132, + MQTTV5_CLIENT_IDENTIFIER_NOT_VALID = 133, + MQTTV5_BAD_USER_NAME_OR_PASSWORD = 134, + MQTTV5_NOT_AUTHORIZED = 135, + MQTTV5_SERVER_UNAVAILABLE = 136, + MQTTV5_SERVER_BUSY = 137, + MQTTV5_BANNED = 138, + MQTTV5_SERVER_SHUTTING_DOWN = 139, + MQTTV5_BAD_AUTHENTICATION_METHOD = 140, + MQTTV5_KEEP_ALIVE_TIMEOUT = 141, + MQTTV5_SESSION_TAKEN_OVER = 142, + MQTTV5_TOPIC_FILTER_INVALID = 143, + MQTTV5_TOPIC_NAME_INVALID = 144, + MQTTV5_PACKET_IDENTIFIER_IN_USE = 145, + MQTTV5_PACKET_IDENTIFIER_NOT_FOUND = 146, + MQTTV5_RECEIVE_MAXIMUM_EXCEEDED = 147, + MQTTV5_TOPIC_ALIAS_INVALID = 148, + MQTTV5_PACKET_TOO_LARGE = 149, + MQTTV5_MESSAGE_RATE_TOO_HIGH = 150, + MQTTV5_QUOTA_EXCEEDED = 151, + MQTTV5_ADMINISTRATIVE_ACTION = 152, + MQTTV5_PAYLOAD_FORMAT_INVALID = 153, + MQTTV5_RETAIN_NOT_SUPPORTED = 154, + MQTTV5_QOS_NOT_SUPPORTED = 155, + MQTTV5_USE_ANOTHER_SERVER = 156, + MQTTV5_SERVER_MOVED = 157, + MQTTV5_SHARED_SUBSCRIPTION_NOT_SUPPORTED = 158, + MQTTV5_CONNECTION_RATE_EXCEEDED = 159, + MQTTV5_MAXIMUM_CONNECT_TIME = 160, + MQTTV5_SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED = 161, + MQTTV5_WILDCARD_SUBSCRIPTION_NOT_SUPPORTED = 162 }; diff --git a/MQTTPacket/test/CMakeLists.txt b/MQTTPacket/test/CMakeLists.txt index 1efa5f9b..6e51141b 100644 --- a/MQTTPacket/test/CMakeLists.txt +++ b/MQTTPacket/test/CMakeLists.txt @@ -19,6 +19,10 @@ ADD_EXECUTABLE( test1.c ) +# Disabling deprecation warnings: +# warning: ‘ftime’ is deprecated [-Wdeprecated-declarations] +target_compile_options(test1 PRIVATE -Wno-deprecated-declarations) + TARGET_LINK_LIBRARIES( test1 paho-embed-mqtt3c @@ -39,6 +43,10 @@ ADD_EXECUTABLE( test1.c ) +# Disabling deprecation warnings: +# warning: ‘ftime’ is deprecated [-Wdeprecated-declarations] +target_compile_options(test15 PRIVATE -Wno-deprecated-declarations) + TARGET_LINK_LIBRARIES( test15 paho-embed-mqtt5c @@ -64,6 +72,10 @@ TARGET_LINK_LIBRARIES( paho-embed-mqtt5c ) +# Disabling deprecation warnings: +# warning: ‘ftime’ is deprecated [-Wdeprecated-declarations] +target_compile_options(test2 PRIVATE -Wno-deprecated-declarations) + ADD_TEST( NAME test2 COMMAND "test2" "--connection" ${MQTT_TEST_BROKER} @@ -80,6 +92,10 @@ ADD_EXECUTABLE( test3.c ) +# Disabling deprecation warnings: +# warning: ‘ftime’ is deprecated [-Wdeprecated-declarations] +target_compile_options(test3 PRIVATE -Wno-deprecated-declarations) + TARGET_LINK_LIBRARIES( test3 paho-embed-mqtt5c diff --git a/MQTTPacket/test/test2.c b/MQTTPacket/test/test2.c index aba2175d..adcbadab 100644 --- a/MQTTPacket/test/test2.c +++ b/MQTTPacket/test/test2.c @@ -800,7 +800,7 @@ int test7(struct Options options) one.identifier = SESSION_EXPIRY_INTERVAL; one.value.integer4 = 45; rc = MQTTProperties_add(&disconnectProperties, &one); - reasonCode = TOPIC_ALIAS_INVALID; // (148) test signed char to unsigned char conversion. + reasonCode = MQTTV5_TOPIC_ALIAS_INVALID; // (148) test signed char to unsigned char conversion. rc = MQTTV5Serialize_disconnect(buf, buflen, reasonCode, &disconnectProperties); assert("good rc from serialize disconnect", rc > 0, "rc was %d\n", rc); @@ -834,7 +834,7 @@ int test8(struct Options options) int count = TOPIC_COUNT; unsigned char reasonCodes[TOPIC_COUNT] = { 2, - QOS_NOT_SUPPORTED // (155) test signed char to unsigned char conversion. + MQTTV5_QOS_NOT_SUPPORTED // (155) test signed char to unsigned char conversion. }; unsigned short msgid2 = 2223; @@ -893,7 +893,7 @@ int test9(struct Options options) int rc = 0; unsigned char buf[100]; int buflen = sizeof(buf); - unsigned char reasonCode = BAD_AUTHENTICATION_METHOD; // (140) test signed char to unsigned char conversion. + unsigned char reasonCode = MQTTV5_BAD_AUTHENTICATION_METHOD; // (140) test signed char to unsigned char conversion. unsigned char reasonCode2 = 44; MQTTProperties properties = MQTTProperties_initializer; From 0696a3b4358603180cb92e76e4316554f9e01d07 Mon Sep 17 00:00:00 2001 From: CIPop Date: Tue, 25 Jul 2023 21:10:38 +0000 Subject: [PATCH 2/3] Updating copyright notice. --- MQTTPacket/src/V5/MQTTReasonCodes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MQTTPacket/src/V5/MQTTReasonCodes.h b/MQTTPacket/src/V5/MQTTReasonCodes.h index 070c978f..176dc1b7 100644 --- a/MQTTPacket/src/V5/MQTTReasonCodes.h +++ b/MQTTPacket/src/V5/MQTTReasonCodes.h @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017 IBM Corp. + * Copyright (c) 2017, 2023 IBM Corp. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 From 023f9a8e00ddc0ae7a190ffba8c59417f122b900 Mon Sep 17 00:00:00 2001 From: CIPop Date: Thu, 27 Jul 2023 23:57:37 +0000 Subject: [PATCH 3/3] Modifying other enum and struct names to avoid public API collisions. --- MQTTClient-C/samples/linux/stdoutsub.c | 12 +- MQTTClient-C/src/MQTTClient.c | 122 +++++----- MQTTClient-C/src/MQTTClient.h | 19 +- MQTTClient-C/test/test1.c | 110 ++++----- MQTTPacket/samples/v5log.c | 318 ++++++++++++------------- MQTTPacket/samples/v5ping.c | 2 +- MQTTPacket/samples/v5ping_nb.c | 2 +- MQTTPacket/samples/v5pub0sub1.c | 8 +- MQTTPacket/samples/v5pub0sub1_nb.c | 8 +- MQTTPacket/samples/v5qos0pub.c | 4 +- MQTTPacket/src/MQTTConnect.h | 14 +- MQTTPacket/src/MQTTSubscribeClient.c | 2 +- MQTTPacket/src/MQTTSubscribeServer.c | 2 +- MQTTPacket/src/V5/MQTTProperties.c | 104 ++++---- MQTTPacket/src/V5/MQTTProperties.h | 72 +++--- MQTTPacket/src/V5/MQTTReasonCodes.h | 92 +++---- MQTTPacket/src/V5/MQTTV5Subscribe.h | 8 +- MQTTPacket/test/test2.c | 26 +- MQTTPacket/test/test3.c | 8 +- 19 files changed, 470 insertions(+), 463 deletions(-) diff --git a/MQTTClient-C/samples/linux/stdoutsub.c b/MQTTClient-C/samples/linux/stdoutsub.c index f57506e7..7ee6b283 100644 --- a/MQTTClient-C/samples/linux/stdoutsub.c +++ b/MQTTClient-C/samples/linux/stdoutsub.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2016 IBM Corp. + * Copyright (c) 2012, 2023 IBM Corp. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -82,7 +82,7 @@ struct opts_struct char* clientid; int nodelimiter; char* delimiter; - enum QoS qos; + enum MQTTQoS qos; char* username; char* password; char* host; @@ -90,7 +90,7 @@ struct opts_struct int showtopics; } opts = { - (char*)"stdout-subscriber", 0, (char*)"\n", QOS2, NULL, NULL, (char*)"localhost", 1883, 0 + (char*)"stdout-subscriber", 0, (char*)"\n", MQTTQOS_2, NULL, NULL, (char*)"localhost", 1883, 0 }; @@ -105,11 +105,11 @@ void getopts(int argc, char** argv) if (++count < argc) { if (strcmp(argv[count], "0") == 0) - opts.qos = QOS0; + opts.qos = MQTTQOS_0; else if (strcmp(argv[count], "1") == 0) - opts.qos = QOS1; + opts.qos = MQTTQOS_1; else if (strcmp(argv[count], "2") == 0) - opts.qos = QOS2; + opts.qos = MQTTQOS_2; else usage(); } diff --git a/MQTTClient-C/src/MQTTClient.c b/MQTTClient-C/src/MQTTClient.c index 6a9beff7..558b6391 100755 --- a/MQTTClient-C/src/MQTTClient.c +++ b/MQTTClient-C/src/MQTTClient.c @@ -33,7 +33,7 @@ static int getNextPacketId(MQTTClient *c) { static int sendPacket(MQTTClient* c, int32_t length, Timer* timer) { - int rc = FAILURE, + int rc = MQTTCLIENT_FAILURE, sent = 0; while (sent < length && !TimerIsExpired(timer)) @@ -46,10 +46,10 @@ static int sendPacket(MQTTClient* c, int32_t length, Timer* timer) if (sent == length) { TimerCountdown(&c->last_sent, c->keepAliveInterval); // record the fact that we have successfully sent the packet - rc = SUCCESS; + rc = MQTTCLIENT_SUCCESS; } else - rc = FAILURE; + rc = MQTTCLIENT_FAILURE; return rc; } @@ -127,7 +127,7 @@ static int readPacket(MQTTClient* c, Timer* timer) if (rem_len > (c->readbuf_size - len)) { - rc = BUFFER_OVERFLOW; + rc = MQTTCLIENT_BUFFER_OVERFLOW; goto exit; } @@ -180,7 +180,7 @@ static char isTopicMatched(char* topicFilter, MQTTString* topicName) int deliverMessage(MQTTClient* c, MQTTString* topicName, MQTTMessage* message) { int i; - int rc = FAILURE; + int rc = MQTTCLIENT_FAILURE; // we have to find the right message handler - indexed by topic for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i) @@ -193,17 +193,17 @@ int deliverMessage(MQTTClient* c, MQTTString* topicName, MQTTMessage* message) MessageData md; NewMessageData(&md, topicName, message); c->messageHandlers[i].fp(&md); - rc = SUCCESS; + rc = MQTTCLIENT_SUCCESS; } } } - if (rc == FAILURE && c->defaultMessageHandler != NULL) + if (rc == MQTTCLIENT_FAILURE && c->defaultMessageHandler != NULL) { MessageData md; NewMessageData(&md, topicName, message); c->defaultMessageHandler(&md); - rc = SUCCESS; + rc = MQTTCLIENT_SUCCESS; } return rc; @@ -212,7 +212,7 @@ int deliverMessage(MQTTClient* c, MQTTString* topicName, MQTTMessage* message) int keepalive(MQTTClient* c) { - int rc = SUCCESS; + int rc = MQTTCLIENT_SUCCESS; if (c->keepAliveInterval == 0) goto exit; @@ -222,7 +222,7 @@ int keepalive(MQTTClient* c) { if (TimerIsExpired(&c->pingresp_timer)) { - rc = FAILURE; /* PINGRESP not received in keepalive interval */ + rc = MQTTCLIENT_FAILURE; /* PINGRESP not received in keepalive interval */ goto exit; } } else @@ -236,7 +236,7 @@ int keepalive(MQTTClient* c) TimerInit(&timer); TimerCountdownMS(&timer, 1000); int32_t len = MQTTSerialize_pingreq(c->buf, c->buf_size); - if (len > 0 && (rc = sendPacket(c, len, &timer)) == SUCCESS) + if (len > 0 && (rc = sendPacket(c, len, &timer)) == MQTTCLIENT_SUCCESS) { c->ping_outstanding = 1; TimerCountdownMS(&c->pingresp_timer, c->keepAliveInterval); @@ -270,7 +270,7 @@ void MQTTCloseSession(MQTTClient* c) int cycle(MQTTClient* c, Timer* timer) { int32_t len = 0, - rc = SUCCESS; + rc = MQTTCLIENT_SUCCESS; int packet_type = readPacket(c, timer); /* read the socket, see what work is due */ @@ -296,19 +296,19 @@ int cycle(MQTTClient* c, Timer* timer) if (MQTTDeserialize_publish(&msg.dup, &intQoS, &msg.retained, &msg.id, &topicName, (unsigned char**)&msg.payload, (int*)&msg.payloadlen, c->readbuf, c->readbuf_size) != 1) goto exit; - msg.qos = (enum QoS)intQoS; + msg.qos = (enum MQTTQoS)intQoS; deliverMessage(c, &topicName, &msg); - if (msg.qos != QOS0) + if (msg.qos != MQTTQOS_0) { - if (msg.qos == QOS1) + if (msg.qos == MQTTQOS_1) len = MQTTSerialize_ack(c->buf, c->buf_size, PUBACK, 0, msg.id); - else if (msg.qos == QOS2) + else if (msg.qos == MQTTQOS_2) len = MQTTSerialize_ack(c->buf, c->buf_size, PUBREC, 0, msg.id); if (len <= 0) - rc = FAILURE; + rc = MQTTCLIENT_FAILURE; else rc = sendPacket(c, len, timer); - if (rc == FAILURE) + if (rc == MQTTCLIENT_FAILURE) goto exit; // there was a problem } break; @@ -319,13 +319,13 @@ int cycle(MQTTClient* c, Timer* timer) unsigned short mypacketid; unsigned char dup, type; if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1) - rc = FAILURE; + rc = MQTTCLIENT_FAILURE; else if ((len = MQTTSerialize_ack(c->buf, c->buf_size, (packet_type == PUBREC) ? PUBREL : PUBCOMP, 0, mypacketid)) <= 0) - rc = FAILURE; - else if ((rc = sendPacket(c, len, timer)) != SUCCESS) // send the PUBREL packet - rc = FAILURE; // there was a problem - if (rc == FAILURE) + rc = MQTTCLIENT_FAILURE; + else if ((rc = sendPacket(c, len, timer)) != MQTTCLIENT_SUCCESS) // send the PUBREL packet + rc = MQTTCLIENT_FAILURE; // there was a problem + if (rc == MQTTCLIENT_FAILURE) goto exit; // there was a problem break; } @@ -337,13 +337,13 @@ int cycle(MQTTClient* c, Timer* timer) break; } - if (keepalive(c) != SUCCESS) { - //check only keepalive FAILURE status so that previous FAILURE status can be considered as FAULT - rc = FAILURE; + if (keepalive(c) != MQTTCLIENT_SUCCESS) { + //check only keepalive MQTTCLIENT_FAILURE status so that previous MQTTCLIENT_FAILURE status can be considered as FAULT + rc = MQTTCLIENT_FAILURE; } exit: - if (rc == SUCCESS) + if (rc == MQTTCLIENT_SUCCESS) rc = packet_type; else if (c->isconnected) MQTTCloseSession(c); @@ -353,7 +353,7 @@ int cycle(MQTTClient* c, Timer* timer) int MQTTYield(MQTTClient* c, int timeout_ms) { - int rc = SUCCESS; + int rc = MQTTCLIENT_SUCCESS; Timer timer; TimerInit(&timer); @@ -363,7 +363,7 @@ int MQTTYield(MQTTClient* c, int timeout_ms) { if (cycle(c, &timer) < 0) { - rc = FAILURE; + rc = MQTTCLIENT_FAILURE; break; } } while (!TimerIsExpired(&timer)); @@ -407,7 +407,7 @@ int MQTTStartTask(MQTTClient* client) int waitfor(MQTTClient* c, int packet_type, Timer* timer) { - int rc = FAILURE; + int rc = MQTTCLIENT_FAILURE; do { @@ -426,7 +426,7 @@ int waitfor(MQTTClient* c, int packet_type, Timer* timer) int MQTTConnectWithResults(MQTTClient* c, MQTTPacket_connectData* options, MQTTConnackData* data) { Timer connect_timer; - int rc = FAILURE; + int rc = MQTTCLIENT_FAILURE; MQTTPacket_connectData default_options = MQTTPacket_connectData_initializer; int32_t len = 0; @@ -447,7 +447,7 @@ int MQTTConnectWithResults(MQTTClient* c, MQTTPacket_connectData* options, MQTTC TimerCountdown(&c->last_received, c->keepAliveInterval); if ((len = MQTTSerialize_connect(c->buf, c->buf_size, options)) <= 0) goto exit; - if ((rc = sendPacket(c, len, &connect_timer)) != SUCCESS) // send the connect packet + if ((rc = sendPacket(c, len, &connect_timer)) != MQTTCLIENT_SUCCESS) // send the connect packet goto exit; // there was a problem // this will be a blocking call, wait for the connack @@ -458,13 +458,13 @@ int MQTTConnectWithResults(MQTTClient* c, MQTTPacket_connectData* options, MQTTC if (MQTTDeserialize_connack(&data->sessionPresent, &data->rc, c->readbuf, c->readbuf_size) == 1) rc = data->rc; else - rc = FAILURE; + rc = MQTTCLIENT_FAILURE; } else - rc = FAILURE; + rc = MQTTCLIENT_FAILURE; exit: - if (rc == SUCCESS) + if (rc == MQTTCLIENT_SUCCESS) { c->isconnected = 1; c->ping_outstanding = 0; @@ -487,7 +487,7 @@ int MQTTConnect(MQTTClient* c, MQTTPacket_connectData* options) int MQTTSetMessageHandler(MQTTClient* c, const char* topicFilter, messageHandler messageHandler) { - int rc = FAILURE; + int rc = MQTTCLIENT_FAILURE; int i = -1; /* first check for an existing matching slot */ @@ -500,19 +500,19 @@ int MQTTSetMessageHandler(MQTTClient* c, const char* topicFilter, messageHandler c->messageHandlers[i].topicFilter = NULL; c->messageHandlers[i].fp = NULL; } - rc = SUCCESS; /* return i when adding new subscription */ + rc = MQTTCLIENT_SUCCESS; /* return i when adding new subscription */ break; } } /* if no existing, look for empty slot (unless we are removing) */ if (messageHandler != NULL) { - if (rc == FAILURE) + if (rc == MQTTCLIENT_FAILURE) { for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i) { if (c->messageHandlers[i].topicFilter == NULL) { - rc = SUCCESS; + rc = MQTTCLIENT_SUCCESS; break; } } @@ -527,10 +527,10 @@ int MQTTSetMessageHandler(MQTTClient* c, const char* topicFilter, messageHandler } -int MQTTSubscribeWithResults(MQTTClient* c, const char* topicFilter, enum QoS qos, +int MQTTSubscribeWithResults(MQTTClient* c, const char* topicFilter, enum MQTTQoS qos, messageHandler messageHandler, MQTTSubackData* data) { - int rc = FAILURE; + int rc = MQTTCLIENT_FAILURE; Timer timer; int32_t len = 0; MQTTString topic = MQTTString_initializer; @@ -549,14 +549,14 @@ int MQTTSubscribeWithResults(MQTTClient* c, const char* topicFilter, enum QoS qo len = MQTTSerialize_subscribe(c->buf, c->buf_size, 0, getNextPacketId(c), 1, &topic, &_qos); if (len <= 0) goto exit; - if ((rc = sendPacket(c, len, &timer)) != SUCCESS) // send the subscribe packet + if ((rc = sendPacket(c, len, &timer)) != MQTTCLIENT_SUCCESS) // send the subscribe packet goto exit; // there was a problem if (waitfor(c, SUBACK, &timer) == SUBACK) // wait for suback { int count = 0; unsigned short mypacketid; - unsigned char grantedQoS = QOS0; + unsigned char grantedQoS = MQTTQOS_0; int retval = MQTTDeserialize_suback(&mypacketid, 1, &count, &grantedQoS, c->readbuf, c->readbuf_size); data->grantedQoS = grantedQoS; if (retval == 1) @@ -566,10 +566,10 @@ int MQTTSubscribeWithResults(MQTTClient* c, const char* topicFilter, enum QoS qo } } else - rc = FAILURE; + rc = MQTTCLIENT_FAILURE; exit: - if (rc == FAILURE) + if (rc == MQTTCLIENT_FAILURE) MQTTCloseSession(c); #if defined(MQTT_TASK) MutexUnlock(&c->mutex); @@ -578,7 +578,7 @@ int MQTTSubscribeWithResults(MQTTClient* c, const char* topicFilter, enum QoS qo } -int MQTTSubscribe(MQTTClient* c, const char* topicFilter, enum QoS qos, +int MQTTSubscribe(MQTTClient* c, const char* topicFilter, enum MQTTQoS qos, messageHandler messageHandler) { MQTTSubackData data; @@ -588,7 +588,7 @@ int MQTTSubscribe(MQTTClient* c, const char* topicFilter, enum QoS qos, int MQTTUnsubscribe(MQTTClient* c, const char* topicFilter) { - int rc = FAILURE; + int rc = MQTTCLIENT_FAILURE; Timer timer; MQTTString topic = MQTTString_initializer; topic.cstring = (char *)topicFilter; @@ -605,7 +605,7 @@ int MQTTUnsubscribe(MQTTClient* c, const char* topicFilter) if ((len = MQTTSerialize_unsubscribe(c->buf, c->buf_size, 0, getNextPacketId(c), 1, &topic)) <= 0) goto exit; - if ((rc = sendPacket(c, len, &timer)) != SUCCESS) // send the subscribe packet + if ((rc = sendPacket(c, len, &timer)) != MQTTCLIENT_SUCCESS) // send the subscribe packet goto exit; // there was a problem if (waitfor(c, UNSUBACK, &timer) == UNSUBACK) @@ -618,10 +618,10 @@ int MQTTUnsubscribe(MQTTClient* c, const char* topicFilter) } } else - rc = FAILURE; + rc = MQTTCLIENT_FAILURE; exit: - if (rc == FAILURE) + if (rc == MQTTCLIENT_FAILURE) MQTTCloseSession(c); #if defined(MQTT_TASK) MutexUnlock(&c->mutex); @@ -632,7 +632,7 @@ int MQTTUnsubscribe(MQTTClient* c, const char* topicFilter) int MQTTPublish(MQTTClient* c, const char* topicName, MQTTMessage* message) { - int rc = FAILURE; + int rc = MQTTCLIENT_FAILURE; Timer timer; MQTTString topic = MQTTString_initializer; topic.cstring = (char *)topicName; @@ -647,43 +647,43 @@ int MQTTPublish(MQTTClient* c, const char* topicName, MQTTMessage* message) TimerInit(&timer); TimerCountdownMS(&timer, c->command_timeout_ms); - if (message->qos == QOS1 || message->qos == QOS2) + if (message->qos == MQTTQOS_1 || message->qos == MQTTQOS_2) message->id = getNextPacketId(c); len = MQTTSerialize_publish(c->buf, c->buf_size, 0, message->qos, message->retained, message->id, topic, (unsigned char*)message->payload, message->payloadlen); if (len <= 0) goto exit; - if ((rc = sendPacket(c, len, &timer)) != SUCCESS) // send the subscribe packet + if ((rc = sendPacket(c, len, &timer)) != MQTTCLIENT_SUCCESS) // send the subscribe packet goto exit; // there was a problem - if (message->qos == QOS1) + if (message->qos == MQTTQOS_1) { if (waitfor(c, PUBACK, &timer) == PUBACK) { unsigned short mypacketid; unsigned char dup, type; if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1) - rc = FAILURE; + rc = MQTTCLIENT_FAILURE; } else - rc = FAILURE; + rc = MQTTCLIENT_FAILURE; } - else if (message->qos == QOS2) + else if (message->qos == MQTTQOS_2) { if (waitfor(c, PUBCOMP, &timer) == PUBCOMP) { unsigned short mypacketid; unsigned char dup, type; if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1) - rc = FAILURE; + rc = MQTTCLIENT_FAILURE; } else - rc = FAILURE; + rc = MQTTCLIENT_FAILURE; } exit: - if (rc == FAILURE) + if (rc == MQTTCLIENT_FAILURE) MQTTCloseSession(c); #if defined(MQTT_TASK) MutexUnlock(&c->mutex); @@ -694,7 +694,7 @@ int MQTTPublish(MQTTClient* c, const char* topicName, MQTTMessage* message) int MQTTDisconnect(MQTTClient* c) { - int rc = FAILURE; + int rc = MQTTCLIENT_FAILURE; Timer timer; // we might wait for incomplete incoming publishes to complete int32_t len = 0; diff --git a/MQTTClient-C/src/MQTTClient.h b/MQTTClient-C/src/MQTTClient.h index 8ff51ef9..0e1e3009 100755 --- a/MQTTClient-C/src/MQTTClient.h +++ b/MQTTClient-C/src/MQTTClient.h @@ -51,10 +51,17 @@ #define MAX_MESSAGE_HANDLERS 5 /* redefinable - how many subscriptions do you want? */ #endif -enum QoS { QOS0, QOS1, QOS2, SUBFAIL=0x80 }; +enum MQTTQoS { + MQTTQOS_0, + MQTTQOS_1, + MQTTQOS_2, + MQTTQOS_SUBFAIL=0x80 }; /* all failure return codes must be negative */ -enum returnCode { BUFFER_OVERFLOW = -2, FAILURE = -1, SUCCESS = 0 }; +enum MQTTClientReturnCode { + MQTTCLIENT_BUFFER_OVERFLOW = -2, + MQTTCLIENT_FAILURE = -1, + MQTTCLIENT_SUCCESS = 0 }; /* The Platform specific header must define the Network and Timer structures and functions * which operate on them. @@ -75,7 +82,7 @@ extern int TimerLeftMS(Timer*); typedef struct MQTTMessage { - enum QoS qos; + enum MQTTQoS qos; unsigned char retained; unsigned char dup; unsigned short id; @@ -97,7 +104,7 @@ typedef struct MQTTConnackData typedef struct MQTTSubackData { - enum QoS grantedQoS; + enum MQTTQoS grantedQoS; } MQTTSubackData; typedef void (*messageHandler)(MessageData*); @@ -181,7 +188,7 @@ DLLExport int MQTTSetMessageHandler(MQTTClient* c, const char* topicFilter, mess * @param message - the message to send * @return success code */ -DLLExport int MQTTSubscribe(MQTTClient* client, const char* topicFilter, enum QoS, messageHandler); +DLLExport int MQTTSubscribe(MQTTClient* client, const char* topicFilter, enum MQTTQoS, messageHandler); /** MQTT Subscribe - send an MQTT subscribe packet and wait for suback before returning. * @param client - the client object to use @@ -190,7 +197,7 @@ DLLExport int MQTTSubscribe(MQTTClient* client, const char* topicFilter, enum Qo * @param data - suback granted QoS returned * @return success code */ -DLLExport int MQTTSubscribeWithResults(MQTTClient* client, const char* topicFilter, enum QoS, messageHandler, MQTTSubackData* data); +DLLExport int MQTTSubscribeWithResults(MQTTClient* client, const char* topicFilter, enum MQTTQoS, messageHandler, MQTTSubackData* data); /** MQTT Subscribe - send an MQTT unsubscribe packet and wait for unsuback before returning. * @param client - the client object to use diff --git a/MQTTClient-C/test/test1.c b/MQTTClient-C/test/test1.c index 21114ed9..24d8d992 100644 --- a/MQTTClient-C/test/test1.c +++ b/MQTTClient-C/test/test1.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2017 IBM Corp. + * Copyright (c) 2009, 2023 IBM Corp. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -323,7 +323,7 @@ void test1_sendAndReceive(MQTTClient* c, int qos, char* test_topic) { test1_message_data = NULL; rc = MQTTPublish(c, test_topic, &pubmsg); - assert("Good rc from publish", rc == SUCCESS, "rc was %d", rc); + assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); /* wait for the message to be received */ wait_seconds = 10; @@ -384,12 +384,12 @@ int test1(struct Options options) MyLog(LOGA_DEBUG, "Connecting"); rc = MQTTConnect(&c, &data); - assert("Good rc from connect", rc == SUCCESS, "rc was %d", rc); - if (rc != SUCCESS) + assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); + if (rc != MQTTCLIENT_SUCCESS) goto exit; rc = MQTTSubscribe(&c, test_topic, subsqos, messageArrived); - assert("Good rc from subscribe", rc == SUCCESS, "rc was %d", rc); + assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); test1_sendAndReceive(&c, 0, test_topic); test1_sendAndReceive(&c, 1, test_topic); @@ -398,16 +398,16 @@ int test1(struct Options options) MyLog(LOGA_DEBUG, "Stopping\n"); rc = MQTTUnsubscribe(&c, test_topic); - assert("Unsubscribe successful", rc == SUCCESS, "rc was %d", rc); + assert("Unsubscribe successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); rc = MQTTDisconnect(&c); - assert("Disconnect successful", rc == SUCCESS, "rc was %d", rc); + assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); /* Just to make sure we can connect again */ NetworkConnect(&n, options.host, options.port); rc = MQTTConnect(&c, &data); - assert("Connect successful", rc == SUCCESS, "rc was %d", rc); + assert("Connect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); rc = MQTTDisconnect(&c); - assert("Disconnect successful", rc == SUCCESS, "rc was %d", rc); + assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); exit: MyLog(LOGA_INFO, "TEST1: test %s. %d tests run, %d failures.", @@ -463,19 +463,19 @@ int test2(struct Options options) MyLog(LOGA_DEBUG, "Connecting"); rc = MQTTConnect(&c, &data); - assert("Good rc from connect", rc == SUCCESS, "rc was %d", rc); - if (rc != SUCCESS) + assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); + if (rc != MQTTCLIENT_SUCCESS) goto exit; rc = MQTTDisconnect(&c); - assert("Disconnect successful", rc == SUCCESS, "rc was %d", rc); + assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); NetworkDisconnect(&n); /* now connect cleansession false */ NetworkConnect(&n, options.host, options.port); data.cleansession = 0; rc = MQTTConnectWithResults(&c, &data, &connack); - assert("Good rc from connect", rc == SUCCESS, "rc was %d", rc); + assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); assert("Good rc in connack", connack.rc == 0, "rc was %d", connack.rc); assert("Session present is 0", connack.sessionPresent == 0, @@ -483,39 +483,39 @@ int test2(struct Options options) /* set up some state */ rc = MQTTSubscribeWithResults(&c, test_topic, subsqos, messageArrived, &suback); - assert("Good rc from subscribe", rc == SUCCESS, "rc was %d", rc); + assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); assert("Good granted QoS", suback.grantedQoS == subsqos, "granted QoS was %d", suback.grantedQoS); rc = MQTTDisconnect(&c); - assert("Disconnect successful", rc == SUCCESS, "rc was %d", rc); + assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); NetworkDisconnect(&n); /* Connect and check sessionPresent */ NetworkConnect(&n, options.host, options.port); rc = MQTTConnectWithResults(&c, &data, &connack); - assert("Connect successful", rc == SUCCESS, "rc was %d", rc); + assert("Connect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); assert("Good rc in connack", connack.rc == 0, "rc was %d", connack.rc); assert("Session present is 1", connack.sessionPresent == 1, "sessionPresent was %d", connack.sessionPresent); rc = MQTTDisconnect(&c); - assert("Disconnect successful", rc == SUCCESS, "rc was %d", rc); + assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); NetworkDisconnect(&n); /* Connect and check sessionPresent is cleared */ data.cleansession = 1; NetworkConnect(&n, options.host, options.port); rc = MQTTConnectWithResults(&c, &data, &connack); - assert("Connect successful", rc == SUCCESS, "rc was %d", rc); + assert("Connect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); assert("Good rc in connack", connack.rc == 0, "rc was %d", connack.rc); assert("Session present is 0", connack.sessionPresent == 0, "sessionPresent was %d", connack.sessionPresent); rc = MQTTDisconnect(&c); - assert("Disconnect successful", rc == SUCCESS, "rc was %d", rc); + assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); NetworkDisconnect(&n); exit: @@ -548,19 +548,19 @@ void messageArrived2(MessageData* md) int check_subs_exist(MQTTClient* c, const char* test_topic, int which) { - int rc = FAILURE; + int rc = MQTTCLIENT_FAILURE; int wait_seconds = 0; memset(&pubmsg, '\0', sizeof(pubmsg)); pubmsg.payload = (void*)"a much longer message that we can shorten to the extent that we need to payload up to 11"; pubmsg.payloadlen = 11; - pubmsg.qos = QOS2; + pubmsg.qos = MQTTQOS_2; pubmsg.retained = 0; pubmsg.dup = 0; test1_message_data = test2_message_data = NULL; rc = MQTTPublish(c, test_topic, &pubmsg); - assert("Good rc from publish", rc == SUCCESS, "rc was %d", rc); + assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); /* wait for the message to be received */ wait_seconds = 10; @@ -570,12 +570,12 @@ int check_subs_exist(MQTTClient* c, const char* test_topic, int which) } rc = (((which == 1 || which == 3) && test1_message_data) || - (which == 2 && test1_message_data == NULL)) ? SUCCESS : FAILURE; - assert("test1 subscription", rc == SUCCESS, "test1_message_data %p\n", + (which == 2 && test1_message_data == NULL)) ? MQTTCLIENT_SUCCESS : MQTTCLIENT_FAILURE; + assert("test1 subscription", rc == MQTTCLIENT_SUCCESS, "test1_message_data %p\n", test1_message_data); rc = (((which == 2 || which == 3) && test2_message_data) || - (which == 1 && test2_message_data == NULL)) ? SUCCESS : FAILURE; - assert("test2 subscription", rc == SUCCESS, "test2_message_data %p\n", + (which == 1 && test2_message_data == NULL)) ? MQTTCLIENT_SUCCESS : MQTTCLIENT_FAILURE; + assert("test2 subscription", rc == MQTTCLIENT_SUCCESS, "test2_message_data %p\n", test2_message_data); return rc; } @@ -583,7 +583,7 @@ int check_subs_exist(MQTTClient* c, const char* test_topic, int which) int test3(struct Options options) { - enum QoS subsqos = QOS2; + enum MQTTQoS subsqos = MQTTQOS_2; Network n; MQTTClient c; int rc; @@ -622,13 +622,13 @@ int test3(struct Options options) MyLog(LOGA_DEBUG, "Connecting"); rc = NetworkConnect(&n, options.host, options.port); - assert("Good rc from TCP connect", rc == SUCCESS, "rc was %d", rc); - if (rc != SUCCESS) + assert("Good rc from TCP connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); + if (rc != MQTTCLIENT_SUCCESS) goto exit; rc = MQTTConnectWithResults(&c, &data, &connack); - assert("Good rc from connect", rc == SUCCESS, "rc was %d", rc); - if (rc != SUCCESS) + assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); + if (rc != MQTTCLIENT_SUCCESS) goto exit; assert("Good rc in connack", connack.rc == 0, "rc was %d", connack.rc); @@ -639,45 +639,45 @@ int test3(struct Options options) "isconnected was %d", MQTTIsConnected(&c)); rc = MQTTDisconnect(&c); - assert("Disconnect successful", rc == SUCCESS, "rc was %d", rc); + assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); NetworkDisconnect(&n); /* reconnect with cleansession false */ data.cleansession = 0; rc = NetworkConnect(&n, options.proxy_host, options.proxy_port); - assert("TCP connect successful", rc == SUCCESS, "rc was %d", rc); + assert("TCP connect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); rc = MQTTConnectWithResults(&c, &data, &connack); - assert("Connect successful", rc == SUCCESS, "rc was %d", rc); + assert("Connect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); assert("Good rc in connack", connack.rc == 0, "rc was %d", connack.rc); assert("Session present is 0", connack.sessionPresent == 0, "sessionPresent was %d", connack.sessionPresent); rc = MQTTSubscribeWithResults(&c, test_topic, subsqos, messageArrived, &suback); - assert("Good rc from subscribe", rc == SUCCESS, "rc was %d", rc); + assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); printf("*** Granted QoS was %d\n", suback.grantedQoS); - assert("Granted QoS rc from subscribe", suback.grantedQoS == (unsigned char)QOS2, + assert("Granted QoS rc from subscribe", suback.grantedQoS == (unsigned char)MQTTQOS_2, "rc was %d", suback.grantedQoS); check_subs_exist(&c, test_topic, 1); rc = MQTTSubscribeWithResults(&c, test_topic, subsqos, messageArrived2, &suback); - assert("Good rc from subscribe", rc == SUCCESS, "rc was %d", rc); - assert("Granted QoS rc from subscribe", suback.grantedQoS == (unsigned char)QOS2, + assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); + assert("Granted QoS rc from subscribe", suback.grantedQoS == (unsigned char)MQTTQOS_2, "rc was %d", suback.grantedQoS); check_subs_exist(&c, test_topic, 2); rc = MQTTDisconnect(&c); - assert("Disconnect successful", rc == SUCCESS, "rc was %d", rc); + assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); NetworkDisconnect(&n); /* reconnect with cleansession false */ data.cleansession = 0; rc = NetworkConnect(&n, options.proxy_host, options.proxy_port); - assert("TCP connect successful", rc == SUCCESS, "rc was %d", rc); + assert("TCP connect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); rc = MQTTConnectWithResults(&c, &data, &connack); - assert("Connect successful", rc == SUCCESS, "rc was %d", rc); + assert("Connect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); assert("Good rc in connack", connack.rc == 0, "rc was %d", connack.rc); assert("Session present is 1", connack.sessionPresent == 1, @@ -686,8 +686,8 @@ int test3(struct Options options) check_subs_exist(&c, test_topic, 2); rc = MQTTSubscribeWithResults(&c, test_topic, subsqos, messageArrived, &suback); - assert("Good rc from subscribe", rc == SUCCESS, "rc was %d", rc); - assert("Granted QoS rc from subscribe", suback.grantedQoS == QOS2, + assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); + assert("Granted QoS rc from subscribe", suback.grantedQoS == MQTTQOS_2, "rc was %d", suback.grantedQoS); check_subs_exist(&c, test_topic, 1); @@ -696,11 +696,11 @@ int test3(struct Options options) memset(&pubmsg, '\0', sizeof(pubmsg)); pubmsg.payload = (void*)"TERMINATE"; pubmsg.payloadlen = strlen((char*)pubmsg.payload); - pubmsg.qos = QOS0; + pubmsg.qos = MQTTQOS_0; pubmsg.retained = 0; pubmsg.dup = 0; rc = MQTTPublish(&c, "MQTTSAS topic", &pubmsg); - assert("Good rc from publish", rc == SUCCESS, "rc was %d", rc); + assert("Good rc from publish", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); // wait for failure to be noticed by keepalive wait_seconds = 20; @@ -715,9 +715,9 @@ int test3(struct Options options) /* reconnect with cleansession false */ data.cleansession = 0; rc = NetworkConnect(&n, options.host, options.port); - assert("TCP connect successful", rc == SUCCESS, "rc was %d", rc); + assert("TCP connect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); rc = MQTTConnectWithResults(&c, &data, &connack); - assert("Connect successful", rc == SUCCESS, "rc was %d", rc); + assert("Connect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); assert("Good rc in connack", connack.rc == 0, "rc was %d", connack.rc); assert("Session present is 1", connack.sessionPresent == 1, @@ -726,36 +726,36 @@ int test3(struct Options options) check_subs_exist(&c, test_topic, 1); rc = MQTTSubscribeWithResults(&c, test_topic, subsqos, messageArrived2, &suback); - assert("Good rc from subscribe", rc == SUCCESS, "rc was %d", rc); - assert("Granted QoS rc from subscribe", suback.grantedQoS == QOS2, + assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); + assert("Granted QoS rc from subscribe", suback.grantedQoS == MQTTQOS_2, "rc was %d", suback.grantedQoS); check_subs_exist(&c, test_topic, 2); rc = MQTTDisconnect(&c); - assert("Disconnect successful", rc == SUCCESS, "rc was %d", rc); + assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); NetworkDisconnect(&n); /* reconnect with cleansession true to clean up both server and client state */ data.cleansession = 1; rc = NetworkConnect(&n, options.host, options.port); - assert("TCP connect successful", rc == SUCCESS, "rc was %d", rc); + assert("TCP connect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); rc = MQTTConnectWithResults(&c, &data, &connack); - assert("Connect successful", rc == SUCCESS, "rc was %d", rc); + assert("Connect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); assert("Good rc in connack", connack.rc == 0, "rc was %d", connack.rc); assert("Session present is 0", connack.sessionPresent == 0, "sessionPresent was %d", connack.sessionPresent); rc = MQTTSubscribeWithResults(&c, test_topic, subsqos, messageArrived2, &suback); - assert("Good rc from subscribe", rc == SUCCESS, "rc was %d", rc); - assert("Granted QoS rc from subscribe", suback.grantedQoS == QOS2, + assert("Good rc from subscribe", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); + assert("Granted QoS rc from subscribe", suback.grantedQoS == MQTTQOS_2, "rc was %d", suback.grantedQoS); check_subs_exist(&c, test_topic, 2); rc = MQTTDisconnect(&c); - assert("Disconnect successful", rc == SUCCESS, "rc was %d", rc); + assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); NetworkDisconnect(&n); exit: diff --git a/MQTTPacket/samples/v5log.c b/MQTTPacket/samples/v5log.c index 326623ae..260c62c5 100644 --- a/MQTTPacket/samples/v5log.c +++ b/MQTTPacket/samples/v5log.c @@ -18,62 +18,62 @@ static const char* v5property_identifier_to_string(int identifier) { switch (identifier) { - case PAYLOAD_FORMAT_INDICATOR: - return "PAYLOAD_FORMAT_INDICATOR"; - case MESSAGE_EXPIRY_INTERVAL: - return "MESSAGE_EXPIRY_INTERVAL"; - case CONTENT_TYPE: - return "CONTENT_TYPE"; - case RESPONSE_TOPIC: - return "RESPONSE_TOPIC"; - case CORRELATION_DATA: - return "CORRELATION_DATA"; - case SUBSCRIPTION_IDENTIFIER: - return "SUBSCRIPTION_IDENTIFIER"; - case SESSION_EXPIRY_INTERVAL: - return "SESSION_EXPIRY_INTERVAL"; - case ASSIGNED_CLIENT_IDENTIFER: - return "ASSIGNED_CLIENT_IDENTIFER"; - case SERVER_KEEP_ALIVE: - return "SERVER_KEEP_ALIVE"; - case AUTHENTICATION_METHOD: - return "AUTHENTICATION_METHOD"; - case AUTHENTICATION_DATA: - return "AUTHENTICATION_DATA"; - case REQUEST_PROBLEM_INFORMATION: - return "REQUEST_PROBLEM_INFORMATION"; - case WILL_DELAY_INTERVAL: - return "WILL_DELAY_INTERVAL"; - case REQUEST_RESPONSE_INFORMATION: - return "REQUEST_RESPONSE_INFORMATION"; - case RESPONSE_INFORMATION: - return "RESPONSE_INFORMATION"; - case SERVER_REFERENCE: - return "SERVER_REFERENCE"; - case REASON_STRING: - return "REASON_STRING"; - case RECEIVE_MAXIMUM: - return "RECEIVE_MAXIMUM"; - case TOPIC_ALIAS_MAXIMUM: - return "TOPIC_ALIAS_MAXIMUM"; - case TOPIC_ALIAS: - return "TOPIC_ALIAS"; - case MAXIMUM_QOS: - return "MAXIMUM_QOS"; - case RETAIN_AVAILABLE: - return "RETAIN_AVAILABLE"; - case USER_PROPERTY: - return "USER_PROPERTY"; - case MAXIMUM_PACKET_SIZE: - return "MAXIMUM_PACKET_SIZE"; - case WILDCARD_SUBSCRIPTION_AVAILABLE: - return "WILDCARD_SUBSCRIPTION_AVAILABLE"; - case SUBSCRIPTION_IDENTIFIER_AVAILABLE: - return "SUBSCRIPTION_IDENTIFIER_AVAILABLE"; - case SHARED_SUBSCRIPTION_AVAILABLE: - return "SHARED_SUBSCRIPTION_AVAILABLE"; + case MQTTPROPERTY_CODE_PAYLOAD_FORMAT_INDICATOR: + return "MQTTPROPERTY_CODE_PAYLOAD_FORMAT_INDICATOR"; + case MQTTPROPERTY_CODE_MESSAGE_EXPIRY_INTERVAL: + return "MQTTPROPERTY_CODE_MESSAGE_EXPIRY_INTERVAL"; + case MQTTPROPERTY_CODE_CONTENT_TYPE: + return "MQTTPROPERTY_CODE_CONTENT_TYPE"; + case MQTTPROPERTY_CODE_RESPONSE_TOPIC: + return "MQTTPROPERTY_CODE_RESPONSE_TOPIC"; + case MQTTPROPERTY_CODE_CORRELATION_DATA: + return "MQTTPROPERTY_CODE_CORRELATION_DATA"; + case MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER: + return "MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER"; + case MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL: + return "MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL"; + case MQTTPROPERTY_CODE_ASSIGNED_CLIENT_IDENTIFER: + return "MQTTPROPERTY_CODE_ASSIGNED_CLIENT_IDENTIFER"; + case MQTTPROPERTY_CODE_SERVER_KEEP_ALIVE: + return "MQTTPROPERTY_CODE_SERVER_KEEP_ALIVE"; + case MQTTPROPERTY_CODE_AUTHENTICATION_METHOD: + return "MQTTPROPERTY_CODE_AUTHENTICATION_METHOD"; + case MQTTPROPERTY_CODE_AUTHENTICATION_DATA: + return "MQTTPROPERTY_CODE_AUTHENTICATION_DATA"; + case MQTTPROPERTY_CODE_REQUEST_PROBLEM_INFORMATION: + return "MQTTPROPERTY_CODE_REQUEST_PROBLEM_INFORMATION"; + case MQTTPROPERTY_CODE_WILL_DELAY_INTERVAL: + return "MQTTPROPERTY_CODE_WILL_DELAY_INTERVAL"; + case MQTTPROPERTY_CODE_REQUEST_RESPONSE_INFORMATION: + return "MQTTPROPERTY_CODE_REQUEST_RESPONSE_INFORMATION"; + case MQTTPROPERTY_CODE_RESPONSE_INFORMATION: + return "MQTTPROPERTY_CODE_RESPONSE_INFORMATION"; + case MQTTPROPERTY_CODE_SERVER_REFERENCE: + return "MQTTPROPERTY_CODE_SERVER_REFERENCE"; + case MQTTPROPERTY_CODE_REASON_STRING: + return "MQTTPROPERTY_CODE_REASON_STRING"; + case MQTTPROPERTY_CODE_RECEIVE_MAXIMUM: + return "MQTTPROPERTY_CODE_RECEIVE_MAXIMUM"; + case MQTTPROPERTY_CODE_TOPIC_ALIAS_MAXIMUM: + return "MQTTPROPERTY_CODE_TOPIC_ALIAS_MAXIMUM"; + case MQTTPROPERTY_CODE_TOPIC_ALIAS: + return "MQTTPROPERTY_CODE_TOPIC_ALIAS"; + case MQTTPROPERTY_CODE_MAXIMUM_QOS: + return "MQTTPROPERTY_CODE_MAXIMUM_QOS"; + case MQTTPROPERTY_CODE_RETAIN_AVAILABLE: + return "MQTTPROPERTY_CODE_RETAIN_AVAILABLE"; + case MQTTPROPERTY_CODE_USER_PROPERTY: + return "MQTTPROPERTY_CODE_USER_PROPERTY"; + case MQTTPROPERTY_CODE_MAXIMUM_PACKET_SIZE: + return "MQTTPROPERTY_CODE_MAXIMUM_PACKET_SIZE"; + case MQTTPROPERTY_CODE_WILDCARD_SUBSCRIPTION_AVAILABLE: + return "MQTTPROPERTY_CODE_WILDCARD_SUBSCRIPTION_AVAILABLE"; + case MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER_AVAILABLE: + return "MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER_AVAILABLE"; + case MQTTPROPERTY_CODE_SHARED_SUBSCRIPTION_AVAILABLE: + return "MQTTPROPERTY_CODE_SHARED_SUBSCRIPTION_AVAILABLE"; default: - return "UNKNOWN"; + return "MQTTPROPERTY_CODE_UNKNOWN"; } } @@ -81,22 +81,22 @@ static const char* v5property_type_to_string(int type) { switch (type) { - case BYTE: - return "BYTE"; - case TWO_BYTE_INTEGER: - return "TWO_BYTE_INTEGER"; - case FOUR_BYTE_INTEGER: - return "FOUR_BYTE_INTEGER"; - case VARIABLE_BYTE_INTEGER: - return "VARIABLE_BYTE_INTEGER"; - case BINARY_DATA: - return "BINARY_DATA"; - case UTF_8_ENCODED_STRING: - return "UTF_8_ENCODED_STRING"; - case UTF_8_STRING_PAIR: - return "UTF_8_STRING_PAIR"; + case MQTTPROPERTY_TYPE_BYTE: + return "MQTTPROPERTY_TYPE_BYTE"; + case MQTTPROPERTY_TYPE_TWO_BYTE_INTEGER: + return "MQTTPROPERTY_TYPE_TWO_BYTE_INTEGER"; + case MQTTPROPERTY_TYPE_FOUR_BYTE_INTEGER: + return "MQTTPROPERTY_TYPE_FOUR_BYTE_INTEGER"; + case MQTTPROPERTY_TYPE_VARIABLE_BYTE_INTEGER: + return "MQTTPROPERTY_TYPE_VARIABLE_BYTE_INTEGER"; + case MQTTPROPERTY_TYPE_BINARY_DATA: + return "MQTTPROPERTY_TYPE_BINARY_DATA"; + case MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING: + return "MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING"; + case MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR: + return "MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR"; default: - return "UNKNOWN"; + return "MQTTPROPERTY_TYPE_UNKNOWN"; } } @@ -108,27 +108,27 @@ void v5property_print(MQTTProperty property) switch(type) { - case BYTE: + case MQTTPROPERTY_TYPE_BYTE: printf("\t%s (%s) = %d\n", identifier_str, type_str, (int)property.value.byte); break; - case TWO_BYTE_INTEGER: + case MQTTPROPERTY_TYPE_TWO_BYTE_INTEGER: printf("\t%s (%s) = %d\n", identifier_str, type_str, (int)property.value.integer2); break; - case FOUR_BYTE_INTEGER: + case MQTTPROPERTY_TYPE_FOUR_BYTE_INTEGER: printf("\t%s (%s) = %d\n", identifier_str, type_str, (int)property.value.integer4); break; - case VARIABLE_BYTE_INTEGER: + case MQTTPROPERTY_TYPE_VARIABLE_BYTE_INTEGER: printf("\t%s (%s) = %d\n", identifier_str, type_str, (int)property.value.integer4); break; - case BINARY_DATA: + case MQTTPROPERTY_TYPE_BINARY_DATA: printf("\t%s (%s) = [%.*s]\n", identifier_str, type_str, property.value.data.len, property.value.data.data); break; - case UTF_8_ENCODED_STRING: + case MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING: printf("\t%s (%s) = [%.*s]\n", identifier_str, type_str, property.value.data.len, property.value.data.data); break; - case UTF_8_STRING_PAIR: + case MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR: printf("\t%s: (%s) = [%.*s], [%.*s]\n", identifier_str, type_str, property.value.string_pair.key.len, property.value.string_pair.key.data, property.value.string_pair.val.len, property.value.string_pair.val.data); @@ -138,91 +138,91 @@ void v5property_print(MQTTProperty property) } } -const char* v5reasoncode_to_string(enum ReasonCodes reasoncode) +const char* v5reasoncode_to_string(enum MQTTReasonCodes reasoncode) { switch (reasoncode) { - case MQTTV5_SUCCESS: - return "MQTTV5_SUCCESS"; - case MQTTV5_NO_MATCHING_SUBSCRIBERS: - return "MQTTV5_NO_MATCHING_SUBSCRIBERS"; - case MQTTV5_NO_SUBSCRIPTION_FOUND: - return "MQTTV5_NO_SUBSCRIPTION_FOUND"; - case MQTTV5_CONTINUE_AUTHENTICATION: - return "MQTTV5_CONTINUE_AUTHENTICATION"; - case MQTTV5_RE_AUTHENTICATE: - return "MQTTV5_RE_AUTHENTICATE"; - case MQTTV5_UNSPECIFIED_ERROR: - return "MQTTV5_UNSPECIFIED_ERROR"; - case MQTTV5_MALFORMED_PACKET: - return "MQTTV5_MALFORMED_PACKET"; - case MQTTV5_PROTOCOL_ERROR: - return "MQTTV5_PROTOCOL_ERROR"; - case MQTTV5_IMPLEMENTATION_SPECIFIC_ERROR: - return "MQTTV5_IMPLEMENTATION_SPECIFIC_ERROR"; - case MQTTV5_UNSUPPORTED_PROTOCOL_VERSION: - return "MQTTV5_UNSUPPORTED_PROTOCOL_VERSION"; - case MQTTV5_CLIENT_IDENTIFIER_NOT_VALID: - return "MQTTV5_CLIENT_IDENTIFIER_NOT_VALID"; - case MQTTV5_BAD_USER_NAME_OR_PASSWORD: - return "MQTTV5_BAD_USER_NAME_OR_PASSWORD"; - case MQTTV5_NOT_AUTHORIZED: - return "MQTTV5_NOT_AUTHORIZED"; - case MQTTV5_SERVER_UNAVAILABLE: - return "MQTTV5_SERVER_UNAVAILABLE"; - case MQTTV5_SERVER_BUSY: - return "MQTTV5_SERVER_BUSY"; - case MQTTV5_BANNED: - return "MQTTV5_BANNED"; - case MQTTV5_SERVER_SHUTTING_DOWN: - return "MQTTV5_SERVER_SHUTTING_DOWN"; - case MQTTV5_BAD_AUTHENTICATION_METHOD: - return "MQTTV5_BAD_AUTHENTICATION_METHOD"; - case MQTTV5_KEEP_ALIVE_TIMEOUT: - return "MQTTV5_KEEP_ALIVE_TIMEOUT"; - case MQTTV5_SESSION_TAKEN_OVER: - return "MQTTV5_SESSION_TAKEN_OVER"; - case MQTTV5_TOPIC_FILTER_INVALID: - return "MQTTV5_TOPIC_FILTER_INVALID"; - case MQTTV5_TOPIC_NAME_INVALID: - return "MQTTV5_TOPIC_NAME_INVALID"; - case MQTTV5_PACKET_IDENTIFIER_IN_USE: - return "MQTTV5_PACKET_IDENTIFIER_IN_USE"; - case MQTTV5_PACKET_IDENTIFIER_NOT_FOUND: - return "MQTTV5_PACKET_IDENTIFIER_NOT_FOUND"; - case MQTTV5_RECEIVE_MAXIMUM_EXCEEDED: - return "MQTTV5_RECEIVE_MAXIMUM_EXCEEDED"; - case MQTTV5_TOPIC_ALIAS_INVALID: - return "MQTTV5_TOPIC_ALIAS_INVALID"; - case MQTTV5_PACKET_TOO_LARGE: - return "MQTTV5_PACKET_TOO_LARGE"; - case MQTTV5_MESSAGE_RATE_TOO_HIGH: - return "MQTTV5_MESSAGE_RATE_TOO_HIGH"; - case MQTTV5_QUOTA_EXCEEDED: - return "MQTTV5_QUOTA_EXCEEDED"; - case MQTTV5_ADMINISTRATIVE_ACTION: - return "MQTTV5_ADMINISTRATIVE_ACTION"; - case MQTTV5_PAYLOAD_FORMAT_INVALID: - return "MQTTV5_PAYLOAD_FORMAT_INVALID"; - case MQTTV5_RETAIN_NOT_SUPPORTED: - return "MQTTV5_RETAIN_NOT_SUPPORTED"; - case MQTTV5_QOS_NOT_SUPPORTED: - return "MQTTV5_QOS_NOT_SUPPORTED"; - case MQTTV5_USE_ANOTHER_SERVER: - return "MQTTV5_USE_ANOTHER_SERVER"; - case MQTTV5_SERVER_MOVED: - return "MQTTV5_SERVER_MOVED"; - case MQTTV5_SHARED_SUBSCRIPTION_NOT_SUPPORTED: - return "MQTTV5_SHARED_SUBSCRIPTION_NOT_SUPPORTED"; - case MQTTV5_CONNECTION_RATE_EXCEEDED: - return "MQTTV5_CONNECTION_RATE_EXCEEDED"; - case MQTTV5_MAXIMUM_CONNECT_TIME: - return "MQTTV5_MAXIMUM_CONNECT_TIME"; - case MQTTV5_SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED: - return "MQTTV5_SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED"; - case MQTTV5_WILDCARD_SUBSCRIPTION_NOT_SUPPORTED: - return "MQTTV5_WILDCARD_SUBSCRIPTION_NOT_SUPPORTED"; + case MQTTREASONCODE_SUCCESS: + return "MQTTREASONCODE_SUCCESS"; + case MQTTREASONCODE_NO_MATCHING_SUBSCRIBERS: + return "MQTTREASONCODE_NO_MATCHING_SUBSCRIBERS"; + case MQTTREASONCODE_NO_SUBSCRIPTION_FOUND: + return "MQTTREASONCODE_NO_SUBSCRIPTION_FOUND"; + case MQTTREASONCODE_CONTINUE_AUTHENTICATION: + return "MQTTREASONCODE_CONTINUE_AUTHENTICATION"; + case MQTTREASONCODE_RE_AUTHENTICATE: + return "MQTTREASONCODE_RE_AUTHENTICATE"; + case MQTTREASONCODE_UNSPECIFIED_ERROR: + return "MQTTREASONCODE_UNSPECIFIED_ERROR"; + case MQTTREASONCODE_MALFORMED_PACKET: + return "MQTTREASONCODE_MALFORMED_PACKET"; + case MQTTREASONCODE_PROTOCOL_ERROR: + return "MQTTREASONCODE_PROTOCOL_ERROR"; + case MQTTREASONCODE_IMPLEMENTATION_SPECIFIC_ERROR: + return "MQTTREASONCODE_IMPLEMENTATION_SPECIFIC_ERROR"; + case MQTTREASONCODE_UNSUPPORTED_PROTOCOL_VERSION: + return "MQTTREASONCODE_UNSUPPORTED_PROTOCOL_VERSION"; + case MQTTREASONCODE_CLIENT_IDENTIFIER_NOT_VALID: + return "MQTTREASONCODE_CLIENT_IDENTIFIER_NOT_VALID"; + case MQTTREASONCODE_BAD_USER_NAME_OR_PASSWORD: + return "MQTTREASONCODE_BAD_USER_NAME_OR_PASSWORD"; + case MQTTREASONCODE_NOT_AUTHORIZED: + return "MQTTREASONCODE_NOT_AUTHORIZED"; + case MQTTREASONCODE_SERVER_UNAVAILABLE: + return "MQTTREASONCODE_SERVER_UNAVAILABLE"; + case MQTTREASONCODE_SERVER_BUSY: + return "MQTTREASONCODE_SERVER_BUSY"; + case MQTTREASONCODE_BANNED: + return "MQTTREASONCODE_BANNED"; + case MQTTREASONCODE_SERVER_SHUTTING_DOWN: + return "MQTTREASONCODE_SERVER_SHUTTING_DOWN"; + case MQTTREASONCODE_BAD_AUTHENTICATION_METHOD: + return "MQTTREASONCODE_BAD_AUTHENTICATION_METHOD"; + case MQTTREASONCODE_KEEP_ALIVE_TIMEOUT: + return "MQTTREASONCODE_KEEP_ALIVE_TIMEOUT"; + case MQTTREASONCODE_SESSION_TAKEN_OVER: + return "MQTTREASONCODE_SESSION_TAKEN_OVER"; + case MQTTREASONCODE_TOPIC_FILTER_INVALID: + return "MQTTREASONCODE_TOPIC_FILTER_INVALID"; + case MQTTREASONCODE_TOPIC_NAME_INVALID: + return "MQTTREASONCODE_TOPIC_NAME_INVALID"; + case MQTTREASONCODE_PACKET_IDENTIFIER_IN_USE: + return "MQTTREASONCODE_PACKET_IDENTIFIER_IN_USE"; + case MQTTREASONCODE_PACKET_IDENTIFIER_NOT_FOUND: + return "MQTTREASONCODE_PACKET_IDENTIFIER_NOT_FOUND"; + case MQTTREASONCODE_RECEIVE_MAXIMUM_EXCEEDED: + return "MQTTREASONCODE_RECEIVE_MAXIMUM_EXCEEDED"; + case MQTTREASONCODE_TOPIC_ALIAS_INVALID: + return "MQTTREASONCODE_TOPIC_ALIAS_INVALID"; + case MQTTREASONCODE_PACKET_TOO_LARGE: + return "MQTTREASONCODE_PACKET_TOO_LARGE"; + case MQTTREASONCODE_MESSAGE_RATE_TOO_HIGH: + return "MQTTREASONCODE_MESSAGE_RATE_TOO_HIGH"; + case MQTTREASONCODE_QUOTA_EXCEEDED: + return "MQTTREASONCODE_QUOTA_EXCEEDED"; + case MQTTREASONCODE_ADMINISTRATIVE_ACTION: + return "MQTTREASONCODE_ADMINISTRATIVE_ACTION"; + case MQTTREASONCODE_PAYLOAD_FORMAT_INVALID: + return "MQTTREASONCODE_PAYLOAD_FORMAT_INVALID"; + case MQTTREASONCODE_RETAIN_NOT_SUPPORTED: + return "MQTTREASONCODE_RETAIN_NOT_SUPPORTED"; + case MQTTREASONCODE_QOS_NOT_SUPPORTED: + return "MQTTREASONCODE_QOS_NOT_SUPPORTED"; + case MQTTREASONCODE_USE_ANOTHER_SERVER: + return "MQTTREASONCODE_USE_ANOTHER_SERVER"; + case MQTTREASONCODE_SERVER_MOVED: + return "MQTTREASONCODE_SERVER_MOVED"; + case MQTTREASONCODE_SHARED_SUBSCRIPTION_NOT_SUPPORTED: + return "MQTTREASONCODE_SHARED_SUBSCRIPTION_NOT_SUPPORTED"; + case MQTTREASONCODE_CONNECTION_RATE_EXCEEDED: + return "MQTTREASONCODE_CONNECTION_RATE_EXCEEDED"; + case MQTTREASONCODE_MAXIMUM_CONNECT_TIME: + return "MQTTREASONCODE_MAXIMUM_CONNECT_TIME"; + case MQTTREASONCODE_SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED: + return "MQTTREASONCODE_SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED"; + case MQTTREASONCODE_WILDCARD_SUBSCRIPTION_NOT_SUPPORTED: + return "MQTTREASONCODE_WILDCARD_SUBSCRIPTION_NOT_SUPPORTED"; default: - return "MQTTV5_UNKNOWN"; + return "MQTTREASONCODE_UNKNOWN"; } } diff --git a/MQTTPacket/samples/v5ping.c b/MQTTPacket/samples/v5ping.c index f8ec17db..21be61c9 100644 --- a/MQTTPacket/samples/v5ping.c +++ b/MQTTPacket/samples/v5ping.c @@ -147,7 +147,7 @@ int main(int argc, char *argv[]) printf("disconnecting\n"); MQTTProperties disconn_properties = MQTTProperties_initializer; - len = MQTTV5Serialize_disconnect(buf, buflen, MQTTV5_NORMAL_DISCONNECTION, &disconn_properties); + len = MQTTV5Serialize_disconnect(buf, buflen, MQTTREASONCODE_NORMAL_DISCONNECTION, &disconn_properties); rc = transport_sendPacketBuffer(mysock, buf, len); diff --git a/MQTTPacket/samples/v5ping_nb.c b/MQTTPacket/samples/v5ping_nb.c index e2d43578..cc5b6837 100644 --- a/MQTTPacket/samples/v5ping_nb.c +++ b/MQTTPacket/samples/v5ping_nb.c @@ -164,7 +164,7 @@ int main(int argc, char *argv[]) printf("disconnecting\n"); MQTTProperties disconn_properties = MQTTProperties_initializer; - len = MQTTV5Serialize_disconnect(buf, buflen, MQTTV5_NORMAL_DISCONNECTION, &disconn_properties); + len = MQTTV5Serialize_disconnect(buf, buflen, MQTTREASONCODE_NORMAL_DISCONNECTION, &disconn_properties); rc = transport_sendPacketBuffer(mysock, buf, len); diff --git a/MQTTPacket/samples/v5pub0sub1.c b/MQTTPacket/samples/v5pub0sub1.c index cbfe6856..95555d1c 100644 --- a/MQTTPacket/samples/v5pub0sub1.c +++ b/MQTTPacket/samples/v5pub0sub1.c @@ -109,7 +109,7 @@ int main(int argc, char *argv[]) printf("MQTTv5 connected: (%d properties)\n", recv_properties.count); for(int i = 0; i < recv_properties.count; i++) { - if (recv_properties.array[i].identifier == TOPIC_ALIAS_MAXIMUM) + if (recv_properties.array[i].identifier == MQTTPROPERTY_CODE_TOPIC_ALIAS_MAXIMUM) { server_topic_alias_max = recv_properties.array[i].value.integer2; } @@ -119,7 +119,7 @@ int main(int argc, char *argv[]) /* subscribe */ MQTTProperties sub_properties = MQTTProperties_initializer; - struct subscribeOptions sub_options = { 0 }; + MQTTSubscribe_options sub_options = { 0 }; topicString.cstring = "substopic"; len = MQTTV5Serialize_subscribe(buf, buflen, 0, msgid, &sub_properties, 1, &topicString, &req_qos, &sub_options); @@ -151,7 +151,7 @@ int main(int argc, char *argv[]) printf("publishing reading\n"); MQTTProperty property_topic_alias = { - .identifier = TOPIC_ALIAS, + .identifier = MQTTPROPERTY_CODE_TOPIC_ALIAS, .value.integer2 = 1 }; @@ -168,7 +168,7 @@ int main(int argc, char *argv[]) char* property_key = "user key"; char* property_value = "user value"; MQTTProperty user_property = { - .identifier = USER_PROPERTY, + .identifier = MQTTPROPERTY_CODE_USER_PROPERTY, .value.string_pair.key.data = property_key, .value.string_pair.key.len = strlen(property_key), .value.string_pair.val.data = property_value, diff --git a/MQTTPacket/samples/v5pub0sub1_nb.c b/MQTTPacket/samples/v5pub0sub1_nb.c index de63ed61..92213790 100644 --- a/MQTTPacket/samples/v5pub0sub1_nb.c +++ b/MQTTPacket/samples/v5pub0sub1_nb.c @@ -113,7 +113,7 @@ int main(int argc, char *argv[]) printf("MQTTv5 connected: (%d properties)\n", recv_properties.count); for(int i = 0; i < recv_properties.count; i++) { - if (recv_properties.array[i].identifier == TOPIC_ALIAS_MAXIMUM) + if (recv_properties.array[i].identifier == MQTTPROPERTY_CODE_TOPIC_ALIAS_MAXIMUM) { server_topic_alias_max = recv_properties.array[i].value.integer2; } @@ -123,7 +123,7 @@ int main(int argc, char *argv[]) /* subscribe */ MQTTProperties sub_properties = MQTTProperties_initializer; - struct subscribeOptions sub_options = { 0 }; + MQTTSubscribe_options sub_options = { 0 }; topicString.cstring = "substopic"; len = MQTTV5Serialize_subscribe(buf, buflen, 0, msgid, &sub_properties, 1, &topicString, &req_qos, &sub_options); @@ -160,7 +160,7 @@ int main(int argc, char *argv[]) printf("publishing reading\n"); MQTTProperty property_topic_alias = { - .identifier = TOPIC_ALIAS, + .identifier = MQTTPROPERTY_CODE_TOPIC_ALIAS, .value.integer2 = 1 }; @@ -177,7 +177,7 @@ int main(int argc, char *argv[]) char* property_key = "user key"; char* property_value = "user value"; MQTTProperty user_property = { - .identifier = USER_PROPERTY, + .identifier = MQTTPROPERTY_CODE_USER_PROPERTY, .value.string_pair.key.data = property_key, .value.string_pair.key.len = strlen(property_key), .value.string_pair.val.data = property_value, diff --git a/MQTTPacket/samples/v5qos0pub.c b/MQTTPacket/samples/v5qos0pub.c index 4404c951..a66ff8c0 100644 --- a/MQTTPacket/samples/v5qos0pub.c +++ b/MQTTPacket/samples/v5qos0pub.c @@ -64,7 +64,7 @@ int main(int argc, char *argv[]) pub_properties.max_count = 1; MQTTProperty v5property; - v5property.identifier = USER_PROPERTY; + v5property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY; v5property.value.string_pair.key.data = "user key"; v5property.value.string_pair.key.len = strlen(v5property.value.string_pair.key.data); v5property.value.string_pair.val.data = "user value"; @@ -80,7 +80,7 @@ int main(int argc, char *argv[]) len += MQTTV5Serialize_publish((unsigned char *)(buf + len), buflen - len, 0, 1, 0, 123, topicString, &pub_properties, (unsigned char *)payload, payloadlen); MQTTProperties disconnect_properties = MQTTProperties_initializer; - len += MQTTV5Serialize_disconnect((unsigned char *)(buf + len), buflen - len, MQTTV5_NORMAL_DISCONNECTION, &disconnect_properties); + len += MQTTV5Serialize_disconnect((unsigned char *)(buf + len), buflen - len, MQTTREASONCODE_NORMAL_DISCONNECTION, &disconnect_properties); rc = transport_sendPacketBuffer(mysock, (unsigned char*)buf, len); if (rc == len) diff --git a/MQTTPacket/src/MQTTConnect.h b/MQTTPacket/src/MQTTConnect.h index 6ff78695..189a5924 100644 --- a/MQTTPacket/src/MQTTConnect.h +++ b/MQTTPacket/src/MQTTConnect.h @@ -22,14 +22,14 @@ #include -enum connack_return_codes +enum MQTTConnackReturnCodes { - MQTT_CONNECTION_ACCEPTED = 0, - MQTT_UNNACCEPTABLE_PROTOCOL = 1, - MQTT_CLIENTID_REJECTED = 2, - MQTT_SERVER_UNAVAILABLE = 3, - MQTT_BAD_USERNAME_OR_PASSWORD = 4, - MQTT_NOT_AUTHORIZED = 5, + MQTTCONNACK_CONNECTION_ACCEPTED = 0, + MQTTCONNACK_UNNACCEPTABLE_PROTOCOL = 1, + MQTTCONNACK_CLIENTID_REJECTED = 2, + MQTTCONNACK_SERVER_UNAVAILABLE = 3, + MQTTCONNACK_BAD_USERNAME_OR_PASSWORD = 4, + MQTTCONNACK_NOT_AUTHORIZED = 5, }; #if !defined(DLLImport) diff --git a/MQTTPacket/src/MQTTSubscribeClient.c b/MQTTPacket/src/MQTTSubscribeClient.c index 434323aa..a62360bc 100644 --- a/MQTTPacket/src/MQTTSubscribeClient.c +++ b/MQTTPacket/src/MQTTSubscribeClient.c @@ -70,7 +70,7 @@ int32_t MQTTSerialize_subscribe(unsigned char* buf, int32_t buflen, unsigned cha } int32_t MQTTV5Serialize_subscribe(unsigned char* buf, int32_t buflen, unsigned char dup, unsigned short packetid, - MQTTProperties* properties, int count, MQTTString topicFilters[], unsigned char requestedQoSs[], struct subscribeOptions options[]) + MQTTProperties* properties, int count, MQTTString topicFilters[], unsigned char requestedQoSs[], MQTTSubscribe_options options[]) #else int32_t MQTTSerialize_subscribe(unsigned char* buf, int32_t buflen, unsigned char dup, unsigned short packetid, int count, MQTTString topicFilters[], unsigned char requestedQoSs[]) diff --git a/MQTTPacket/src/MQTTSubscribeServer.c b/MQTTPacket/src/MQTTSubscribeServer.c index 878427bc..23f8e1e4 100644 --- a/MQTTPacket/src/MQTTSubscribeServer.c +++ b/MQTTPacket/src/MQTTSubscribeServer.c @@ -47,7 +47,7 @@ int32_t MQTTDeserialize_subscribe(unsigned char* dup, unsigned short* packetid, } int32_t MQTTV5Deserialize_subscribe(unsigned char* dup, unsigned short* packetid, MQTTProperties* properties, - int maxcount, int* count, MQTTString topicFilters[], unsigned char requestedQoSs[], struct subscribeOptions options[], + int maxcount, int* count, MQTTString topicFilters[], unsigned char requestedQoSs[], MQTTSubscribe_options options[], unsigned char* buf, int32_t buflen) #else int32_t MQTTDeserialize_subscribe(unsigned char* dup, unsigned short* packetid, int maxcount, int* count, MQTTString topicFilters[], diff --git a/MQTTPacket/src/V5/MQTTProperties.c b/MQTTPacket/src/V5/MQTTProperties.c index 44445e93..a1d5c629 100644 --- a/MQTTPacket/src/V5/MQTTProperties.c +++ b/MQTTPacket/src/V5/MQTTProperties.c @@ -20,37 +20,37 @@ struct nameToType { - enum PropertyNames name; - enum PropertyTypes type; + enum MQTTPropertyNames name; + enum MQTTPropertyTypes type; } namesToTypes[] = { - {PAYLOAD_FORMAT_INDICATOR, BYTE}, - {MESSAGE_EXPIRY_INTERVAL, FOUR_BYTE_INTEGER}, - {CONTENT_TYPE, UTF_8_ENCODED_STRING}, - {RESPONSE_TOPIC, UTF_8_ENCODED_STRING}, - {CORRELATION_DATA, BINARY_DATA}, - {SUBSCRIPTION_IDENTIFIER, VARIABLE_BYTE_INTEGER}, - {SESSION_EXPIRY_INTERVAL, FOUR_BYTE_INTEGER}, - {ASSIGNED_CLIENT_IDENTIFER, UTF_8_ENCODED_STRING}, - {SERVER_KEEP_ALIVE, TWO_BYTE_INTEGER}, - {AUTHENTICATION_METHOD, UTF_8_ENCODED_STRING}, - {AUTHENTICATION_DATA, BINARY_DATA}, - {REQUEST_PROBLEM_INFORMATION, BYTE}, - {WILL_DELAY_INTERVAL, FOUR_BYTE_INTEGER}, - {REQUEST_RESPONSE_INFORMATION, BYTE}, - {RESPONSE_INFORMATION, UTF_8_ENCODED_STRING}, - {SERVER_REFERENCE, UTF_8_ENCODED_STRING}, - {REASON_STRING, UTF_8_ENCODED_STRING}, - {RECEIVE_MAXIMUM, TWO_BYTE_INTEGER}, - {TOPIC_ALIAS_MAXIMUM, TWO_BYTE_INTEGER}, - {TOPIC_ALIAS, TWO_BYTE_INTEGER}, - {MAXIMUM_QOS, BYTE}, - {RETAIN_AVAILABLE, BYTE}, - {USER_PROPERTY, UTF_8_STRING_PAIR}, - {MAXIMUM_PACKET_SIZE, FOUR_BYTE_INTEGER}, - {WILDCARD_SUBSCRIPTION_AVAILABLE, BYTE}, - {SUBSCRIPTION_IDENTIFIER_AVAILABLE, BYTE}, - {SHARED_SUBSCRIPTION_AVAILABLE, BYTE} + {MQTTPROPERTY_CODE_PAYLOAD_FORMAT_INDICATOR, MQTTPROPERTY_TYPE_BYTE}, + {MQTTPROPERTY_CODE_MESSAGE_EXPIRY_INTERVAL, MQTTPROPERTY_TYPE_FOUR_BYTE_INTEGER}, + {MQTTPROPERTY_CODE_CONTENT_TYPE, MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING}, + {MQTTPROPERTY_CODE_RESPONSE_TOPIC, MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING}, + {MQTTPROPERTY_CODE_CORRELATION_DATA, MQTTPROPERTY_TYPE_BINARY_DATA}, + {MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER, MQTTPROPERTY_TYPE_VARIABLE_BYTE_INTEGER}, + {MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL, MQTTPROPERTY_TYPE_FOUR_BYTE_INTEGER}, + {MQTTPROPERTY_CODE_ASSIGNED_CLIENT_IDENTIFER, MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING}, + {MQTTPROPERTY_CODE_SERVER_KEEP_ALIVE, MQTTPROPERTY_TYPE_TWO_BYTE_INTEGER}, + {MQTTPROPERTY_CODE_AUTHENTICATION_METHOD, MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING}, + {MQTTPROPERTY_CODE_AUTHENTICATION_DATA, MQTTPROPERTY_TYPE_BINARY_DATA}, + {MQTTPROPERTY_CODE_REQUEST_PROBLEM_INFORMATION, MQTTPROPERTY_TYPE_BYTE}, + {MQTTPROPERTY_CODE_WILL_DELAY_INTERVAL, MQTTPROPERTY_TYPE_FOUR_BYTE_INTEGER}, + {MQTTPROPERTY_CODE_REQUEST_RESPONSE_INFORMATION, MQTTPROPERTY_TYPE_BYTE}, + {MQTTPROPERTY_CODE_RESPONSE_INFORMATION, MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING}, + {MQTTPROPERTY_CODE_SERVER_REFERENCE, MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING}, + {MQTTPROPERTY_CODE_REASON_STRING, MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING}, + {MQTTPROPERTY_CODE_RECEIVE_MAXIMUM, MQTTPROPERTY_TYPE_TWO_BYTE_INTEGER}, + {MQTTPROPERTY_CODE_TOPIC_ALIAS_MAXIMUM, MQTTPROPERTY_TYPE_TWO_BYTE_INTEGER}, + {MQTTPROPERTY_CODE_TOPIC_ALIAS, MQTTPROPERTY_TYPE_TWO_BYTE_INTEGER}, + {MQTTPROPERTY_CODE_MAXIMUM_QOS, MQTTPROPERTY_TYPE_BYTE}, + {MQTTPROPERTY_CODE_RETAIN_AVAILABLE, MQTTPROPERTY_TYPE_BYTE}, + {MQTTPROPERTY_CODE_USER_PROPERTY, MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR}, + {MQTTPROPERTY_CODE_MAXIMUM_PACKET_SIZE, MQTTPROPERTY_TYPE_FOUR_BYTE_INTEGER}, + {MQTTPROPERTY_CODE_WILDCARD_SUBSCRIPTION_AVAILABLE, MQTTPROPERTY_TYPE_BYTE}, + {MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER_AVAILABLE, MQTTPROPERTY_TYPE_BYTE}, + {MQTTPROPERTY_CODE_SHARED_SUBSCRIPTION_AVAILABLE, MQTTPROPERTY_TYPE_BYTE} }; @@ -93,16 +93,16 @@ int MQTTProperties_add(MQTTProperties* props, MQTTProperty* prop) /* calculate length */ switch (type) { - case BYTE: + case MQTTPROPERTY_TYPE_BYTE: len = 1; break; - case TWO_BYTE_INTEGER: + case MQTTPROPERTY_TYPE_TWO_BYTE_INTEGER: len = 2; break; - case FOUR_BYTE_INTEGER: + case MQTTPROPERTY_TYPE_FOUR_BYTE_INTEGER: len = 4; break; - case VARIABLE_BYTE_INTEGER: + case MQTTPROPERTY_TYPE_VARIABLE_BYTE_INTEGER: if (prop->value.integer4 >= 0 && prop->value.integer4 <= 127) len = 1; else if (prop->value.integer4 >= 128 && prop->value.integer4 <= 16383) @@ -112,11 +112,11 @@ int MQTTProperties_add(MQTTProperties* props, MQTTProperty* prop) else if (prop->value.integer4 >= 2097152 && prop->value.integer4 < 268435455) len = 4; break; - case BINARY_DATA: - case UTF_8_ENCODED_STRING: + case MQTTPROPERTY_TYPE_BINARY_DATA: + case MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING: len = 2 + prop->value.data.len; break; - case UTF_8_STRING_PAIR: + case MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR: len = 2 + prop->value.string_pair.key.len; len += 2 + prop->value.string_pair.val.len; break; @@ -134,32 +134,32 @@ int MQTTProperty_write(unsigned char** pptr, MQTTProperty* prop) type = -1; type = MQTTProperty_getType(prop->identifier); - if (type >= BYTE && type <= UTF_8_STRING_PAIR) + if (type >= MQTTPROPERTY_TYPE_BYTE && type <= MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR) { writeChar(pptr, prop->identifier); switch (type) { - case BYTE: + case MQTTPROPERTY_TYPE_BYTE: writeChar(pptr, prop->value.byte); rc = 1; break; - case TWO_BYTE_INTEGER: + case MQTTPROPERTY_TYPE_TWO_BYTE_INTEGER: writeInt(pptr, prop->value.integer2); rc = 2; break; - case FOUR_BYTE_INTEGER: + case MQTTPROPERTY_TYPE_FOUR_BYTE_INTEGER: writeInt4(pptr, prop->value.integer4); rc = 4; break; - case VARIABLE_BYTE_INTEGER: + case MQTTPROPERTY_TYPE_VARIABLE_BYTE_INTEGER: rc = MQTTPacket_encode(*pptr, prop->value.integer4); break; - case BINARY_DATA: - case UTF_8_ENCODED_STRING: + case MQTTPROPERTY_TYPE_BINARY_DATA: + case MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING: writeMQTTLenString(pptr, prop->value.data); rc = prop->value.data.len + 2; /* include length field */ break; - case UTF_8_STRING_PAIR: + case MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR: writeMQTTLenString(pptr, prop->value.string_pair.key); writeMQTTLenString(pptr, prop->value.string_pair.val); rc = prop->value.string_pair.key.len + prop->value.string_pair.val.len + 4; /* include length fields */ @@ -206,31 +206,31 @@ int MQTTProperty_read(MQTTProperty* prop, unsigned char** pptr, unsigned char* e prop->identifier = (unsigned char)readChar(pptr); type = MQTTProperty_getType(prop->identifier); - if (type >= BYTE && type <= UTF_8_STRING_PAIR) + if (type >= MQTTPROPERTY_TYPE_BYTE && type <= MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR) { switch (type) { - case BYTE: + case MQTTPROPERTY_TYPE_BYTE: prop->value.byte = readChar(pptr); len = 1; break; - case TWO_BYTE_INTEGER: + case MQTTPROPERTY_TYPE_TWO_BYTE_INTEGER: prop->value.integer2 = readInt(pptr); len = 2; break; - case FOUR_BYTE_INTEGER: + case MQTTPROPERTY_TYPE_FOUR_BYTE_INTEGER: prop->value.integer4 = readInt4(pptr); len = 4; break; - case VARIABLE_BYTE_INTEGER: + case MQTTPROPERTY_TYPE_VARIABLE_BYTE_INTEGER: len = MQTTPacket_decodeBuf(*pptr, &prop->value.integer4); *pptr += len; break; - case BINARY_DATA: - case UTF_8_ENCODED_STRING: + case MQTTPROPERTY_TYPE_BINARY_DATA: + case MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING: len = MQTTLenStringRead(&prop->value.data, pptr, enddata); break; - case UTF_8_STRING_PAIR: + case MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR: len = MQTTLenStringRead(&prop->value.string_pair.key, pptr, enddata); len += MQTTLenStringRead(&prop->value.string_pair.val, pptr, enddata); break; diff --git a/MQTTPacket/src/V5/MQTTProperties.h b/MQTTPacket/src/V5/MQTTProperties.h index 9e8069b8..39bf5061 100644 --- a/MQTTPacket/src/V5/MQTTProperties.h +++ b/MQTTPacket/src/V5/MQTTProperties.h @@ -15,44 +15,44 @@ *******************************************************************************/ -enum PropertyNames { - PAYLOAD_FORMAT_INDICATOR = 1, - MESSAGE_EXPIRY_INTERVAL = 2, - CONTENT_TYPE = 3, - RESPONSE_TOPIC = 8, - CORRELATION_DATA = 9, - SUBSCRIPTION_IDENTIFIER = 11, - SESSION_EXPIRY_INTERVAL = 17, - ASSIGNED_CLIENT_IDENTIFER = 18, - SERVER_KEEP_ALIVE = 19, - AUTHENTICATION_METHOD = 21, - AUTHENTICATION_DATA = 22, - REQUEST_PROBLEM_INFORMATION = 23, - WILL_DELAY_INTERVAL = 24, - REQUEST_RESPONSE_INFORMATION = 25, - RESPONSE_INFORMATION = 26, - SERVER_REFERENCE = 28, - REASON_STRING = 31, - RECEIVE_MAXIMUM = 33, - TOPIC_ALIAS_MAXIMUM = 34, - TOPIC_ALIAS = 35, - MAXIMUM_QOS = 36, - RETAIN_AVAILABLE = 37, - USER_PROPERTY = 38, - MAXIMUM_PACKET_SIZE = 39, - WILDCARD_SUBSCRIPTION_AVAILABLE = 40, - SUBSCRIPTION_IDENTIFIER_AVAILABLE = 41, - SHARED_SUBSCRIPTION_AVAILABLE = 42 +enum MQTTPropertyNames { + MQTTPROPERTY_CODE_PAYLOAD_FORMAT_INDICATOR = 1, + MQTTPROPERTY_CODE_MESSAGE_EXPIRY_INTERVAL = 2, + MQTTPROPERTY_CODE_CONTENT_TYPE = 3, + MQTTPROPERTY_CODE_RESPONSE_TOPIC = 8, + MQTTPROPERTY_CODE_CORRELATION_DATA = 9, + MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER = 11, + MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL = 17, + MQTTPROPERTY_CODE_ASSIGNED_CLIENT_IDENTIFER = 18, + MQTTPROPERTY_CODE_SERVER_KEEP_ALIVE = 19, + MQTTPROPERTY_CODE_AUTHENTICATION_METHOD = 21, + MQTTPROPERTY_CODE_AUTHENTICATION_DATA = 22, + MQTTPROPERTY_CODE_REQUEST_PROBLEM_INFORMATION = 23, + MQTTPROPERTY_CODE_WILL_DELAY_INTERVAL = 24, + MQTTPROPERTY_CODE_REQUEST_RESPONSE_INFORMATION = 25, + MQTTPROPERTY_CODE_RESPONSE_INFORMATION = 26, + MQTTPROPERTY_CODE_SERVER_REFERENCE = 28, + MQTTPROPERTY_CODE_REASON_STRING = 31, + MQTTPROPERTY_CODE_RECEIVE_MAXIMUM = 33, + MQTTPROPERTY_CODE_TOPIC_ALIAS_MAXIMUM = 34, + MQTTPROPERTY_CODE_TOPIC_ALIAS = 35, + MQTTPROPERTY_CODE_MAXIMUM_QOS = 36, + MQTTPROPERTY_CODE_RETAIN_AVAILABLE = 37, + MQTTPROPERTY_CODE_USER_PROPERTY = 38, + MQTTPROPERTY_CODE_MAXIMUM_PACKET_SIZE = 39, + MQTTPROPERTY_CODE_WILDCARD_SUBSCRIPTION_AVAILABLE = 40, + MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER_AVAILABLE = 41, + MQTTPROPERTY_CODE_SHARED_SUBSCRIPTION_AVAILABLE = 42 }; -enum PropertyTypes { - BYTE, - TWO_BYTE_INTEGER, - FOUR_BYTE_INTEGER, - VARIABLE_BYTE_INTEGER, - BINARY_DATA, - UTF_8_ENCODED_STRING, - UTF_8_STRING_PAIR +enum MQTTPropertyTypes { + MQTTPROPERTY_TYPE_BYTE, + MQTTPROPERTY_TYPE_TWO_BYTE_INTEGER, + MQTTPROPERTY_TYPE_FOUR_BYTE_INTEGER, + MQTTPROPERTY_TYPE_VARIABLE_BYTE_INTEGER, + MQTTPROPERTY_TYPE_BINARY_DATA, + MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING, + MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR }; typedef struct { diff --git a/MQTTPacket/src/V5/MQTTReasonCodes.h b/MQTTPacket/src/V5/MQTTReasonCodes.h index 176dc1b7..70346b1b 100644 --- a/MQTTPacket/src/V5/MQTTReasonCodes.h +++ b/MQTTPacket/src/V5/MQTTReasonCodes.h @@ -14,50 +14,50 @@ * Ian Craggs - initial API and implementation and/or initial documentation *******************************************************************************/ -enum ReasonCodes { - MQTTV5_SUCCESS = 0, - MQTTV5_NORMAL_DISCONNECTION = 0, - MQTTV5_GRANTED_QOS_0 = 0, - MQTTV5_GRANTED_QOS_1 = 1, - MQTTV5_GRANTED_QOS_2 = 2, - MQTTV5_DISCONNECT_WITH_WILL_MESSAGE = 4, - MQTTV5_NO_MATCHING_SUBSCRIBERS = 16, - MQTTV5_NO_SUBSCRIPTION_FOUND = 17, - MQTTV5_CONTINUE_AUTHENTICATION = 24, - MQTTV5_RE_AUTHENTICATE = 25, - MQTTV5_UNSPECIFIED_ERROR = 128, - MQTTV5_MALFORMED_PACKET = 129, - MQTTV5_PROTOCOL_ERROR = 130, - MQTTV5_IMPLEMENTATION_SPECIFIC_ERROR = 131, - MQTTV5_UNSUPPORTED_PROTOCOL_VERSION = 132, - MQTTV5_CLIENT_IDENTIFIER_NOT_VALID = 133, - MQTTV5_BAD_USER_NAME_OR_PASSWORD = 134, - MQTTV5_NOT_AUTHORIZED = 135, - MQTTV5_SERVER_UNAVAILABLE = 136, - MQTTV5_SERVER_BUSY = 137, - MQTTV5_BANNED = 138, - MQTTV5_SERVER_SHUTTING_DOWN = 139, - MQTTV5_BAD_AUTHENTICATION_METHOD = 140, - MQTTV5_KEEP_ALIVE_TIMEOUT = 141, - MQTTV5_SESSION_TAKEN_OVER = 142, - MQTTV5_TOPIC_FILTER_INVALID = 143, - MQTTV5_TOPIC_NAME_INVALID = 144, - MQTTV5_PACKET_IDENTIFIER_IN_USE = 145, - MQTTV5_PACKET_IDENTIFIER_NOT_FOUND = 146, - MQTTV5_RECEIVE_MAXIMUM_EXCEEDED = 147, - MQTTV5_TOPIC_ALIAS_INVALID = 148, - MQTTV5_PACKET_TOO_LARGE = 149, - MQTTV5_MESSAGE_RATE_TOO_HIGH = 150, - MQTTV5_QUOTA_EXCEEDED = 151, - MQTTV5_ADMINISTRATIVE_ACTION = 152, - MQTTV5_PAYLOAD_FORMAT_INVALID = 153, - MQTTV5_RETAIN_NOT_SUPPORTED = 154, - MQTTV5_QOS_NOT_SUPPORTED = 155, - MQTTV5_USE_ANOTHER_SERVER = 156, - MQTTV5_SERVER_MOVED = 157, - MQTTV5_SHARED_SUBSCRIPTION_NOT_SUPPORTED = 158, - MQTTV5_CONNECTION_RATE_EXCEEDED = 159, - MQTTV5_MAXIMUM_CONNECT_TIME = 160, - MQTTV5_SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED = 161, - MQTTV5_WILDCARD_SUBSCRIPTION_NOT_SUPPORTED = 162 +enum MQTTReasonCodes { + MQTTREASONCODE_SUCCESS = 0, + MQTTREASONCODE_NORMAL_DISCONNECTION = 0, + MQTTREASONCODE_GRANTED_QOS_0 = 0, + MQTTREASONCODE_GRANTED_QOS_1 = 1, + MQTTREASONCODE_GRANTED_QOS_2 = 2, + MQTTREASONCODE_DISCONNECT_WITH_WILL_MESSAGE = 4, + MQTTREASONCODE_NO_MATCHING_SUBSCRIBERS = 16, + MQTTREASONCODE_NO_SUBSCRIPTION_FOUND = 17, + MQTTREASONCODE_CONTINUE_AUTHENTICATION = 24, + MQTTREASONCODE_RE_AUTHENTICATE = 25, + MQTTREASONCODE_UNSPECIFIED_ERROR = 128, + MQTTREASONCODE_MALFORMED_PACKET = 129, + MQTTREASONCODE_PROTOCOL_ERROR = 130, + MQTTREASONCODE_IMPLEMENTATION_SPECIFIC_ERROR = 131, + MQTTREASONCODE_UNSUPPORTED_PROTOCOL_VERSION = 132, + MQTTREASONCODE_CLIENT_IDENTIFIER_NOT_VALID = 133, + MQTTREASONCODE_BAD_USER_NAME_OR_PASSWORD = 134, + MQTTREASONCODE_NOT_AUTHORIZED = 135, + MQTTREASONCODE_SERVER_UNAVAILABLE = 136, + MQTTREASONCODE_SERVER_BUSY = 137, + MQTTREASONCODE_BANNED = 138, + MQTTREASONCODE_SERVER_SHUTTING_DOWN = 139, + MQTTREASONCODE_BAD_AUTHENTICATION_METHOD = 140, + MQTTREASONCODE_KEEP_ALIVE_TIMEOUT = 141, + MQTTREASONCODE_SESSION_TAKEN_OVER = 142, + MQTTREASONCODE_TOPIC_FILTER_INVALID = 143, + MQTTREASONCODE_TOPIC_NAME_INVALID = 144, + MQTTREASONCODE_PACKET_IDENTIFIER_IN_USE = 145, + MQTTREASONCODE_PACKET_IDENTIFIER_NOT_FOUND = 146, + MQTTREASONCODE_RECEIVE_MAXIMUM_EXCEEDED = 147, + MQTTREASONCODE_TOPIC_ALIAS_INVALID = 148, + MQTTREASONCODE_PACKET_TOO_LARGE = 149, + MQTTREASONCODE_MESSAGE_RATE_TOO_HIGH = 150, + MQTTREASONCODE_QUOTA_EXCEEDED = 151, + MQTTREASONCODE_ADMINISTRATIVE_ACTION = 152, + MQTTREASONCODE_PAYLOAD_FORMAT_INVALID = 153, + MQTTREASONCODE_RETAIN_NOT_SUPPORTED = 154, + MQTTREASONCODE_QOS_NOT_SUPPORTED = 155, + MQTTREASONCODE_USE_ANOTHER_SERVER = 156, + MQTTREASONCODE_SERVER_MOVED = 157, + MQTTREASONCODE_SHARED_SUBSCRIPTION_NOT_SUPPORTED = 158, + MQTTREASONCODE_CONNECTION_RATE_EXCEEDED = 159, + MQTTREASONCODE_MAXIMUM_CONNECT_TIME = 160, + MQTTREASONCODE_SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED = 161, + MQTTREASONCODE_WILDCARD_SUBSCRIPTION_NOT_SUPPORTED = 162 }; diff --git a/MQTTPacket/src/V5/MQTTV5Subscribe.h b/MQTTPacket/src/V5/MQTTV5Subscribe.h index e19aed75..6cb914a0 100644 --- a/MQTTPacket/src/V5/MQTTV5Subscribe.h +++ b/MQTTPacket/src/V5/MQTTV5Subscribe.h @@ -24,18 +24,18 @@ #define DLLExport #endif -struct subscribeOptions +typedef struct MQTTSubscribe_options { unsigned char noLocal; /* 0 or 1 */ unsigned char retainAsPublished; /* 0 or 1 */ unsigned char retainHandling; /* 0, 1 or 2 */ -}; +} MQTTSubscribe_options; DLLExport int32_t MQTTV5Serialize_subscribe(unsigned char* buf, int32_t buflen, unsigned char dup, unsigned short packetid, - MQTTProperties* properties, int count, MQTTString topicFilters[], unsigned char requestedQoSs[], struct subscribeOptions options[]); + MQTTProperties* properties, int count, MQTTString topicFilters[], unsigned char requestedQoSs[], MQTTSubscribe_options options[]); DLLExport int32_t MQTTV5Deserialize_subscribe(unsigned char* dup, unsigned short* packetid, MQTTProperties* properties, - int maxcount, int* count, MQTTString topicFilters[], unsigned char requestedQoSs[], struct subscribeOptions options[], + int maxcount, int* count, MQTTString topicFilters[], unsigned char requestedQoSs[], MQTTSubscribe_options options[], unsigned char* buf, int len); DLLExport int32_t MQTTV5Serialize_suback(unsigned char* buf, int32_t buflen, unsigned short packetid, diff --git a/MQTTPacket/test/test2.c b/MQTTPacket/test/test2.c index adcbadab..7e0558ac 100644 --- a/MQTTPacket/test/test2.c +++ b/MQTTPacket/test/test2.c @@ -375,7 +375,7 @@ int test1(struct Options options) connectProperties.array = connect_props; MQTTProperty one; - one.identifier = SESSION_EXPIRY_INTERVAL; + one.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL; one.value.integer4 = 45; rc = MQTTProperties_add(&connectProperties, &one); @@ -455,7 +455,7 @@ int test2(struct Options options) outProperties.array = out_props; MQTTProperty one; - one.identifier = SESSION_EXPIRY_INTERVAL; + one.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL; one.value.integer4 = 45; rc = MQTTProperties_add(&properties, &one); @@ -518,7 +518,7 @@ int test3(struct Options options) MQTTString topicStrings2[TOPIC_COUNT] = { MQTTString_initializer, MQTTString_initializer }; unsigned char req_qoss2[TOPIC_COUNT] = {0, 0}; - struct subscribeOptions subscribeOptions[2] = {{1, 1, 1}, {1, 0, 2}}, + MQTTSubscribe_options subscribeOptions[2] = {{1, 1, 1}, {1, 0, 2}}, outSubscribeOptions[2] = {{0, 0, 0}, {0, 0, 0}}; MQTTProperties properties = MQTTProperties_initializer; @@ -532,7 +532,7 @@ int test3(struct Options options) outProperties.array = out_props; MQTTProperty one; - one.identifier = USER_PROPERTY; + one.identifier = MQTTPROPERTY_CODE_USER_PROPERTY; one.value.string_pair.key.data = "user property name"; one.value.string_pair.key.len = strlen(one.value.string_pair.key.data); one.value.string_pair.val.data = "user property value"; @@ -616,7 +616,7 @@ int test4(struct Options options) outProperties.array = out_props; MQTTProperty one; - one.identifier = USER_PROPERTY; + one.identifier = MQTTPROPERTY_CODE_USER_PROPERTY; one.value.string_pair.key.data = "user property name"; one.value.string_pair.key.len = strlen(one.value.string_pair.key.data); one.value.string_pair.val.data = "user property value"; @@ -681,7 +681,7 @@ int test5(struct Options options) outProperties.array = out_props; MQTTProperty one; - one.identifier = USER_PROPERTY; + one.identifier = MQTTPROPERTY_CODE_USER_PROPERTY; one.value.string_pair.key.data = "user property name"; one.value.string_pair.key.len = strlen(one.value.string_pair.key.data); one.value.string_pair.val.data = "user property value"; @@ -750,7 +750,7 @@ int test6(struct Options options) outConnackProperties.array = out_connack_props; MQTTProperty one; - one.identifier = SESSION_EXPIRY_INTERVAL; + one.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL; one.value.integer4 = 45; rc = MQTTProperties_add(&connackProperties, &one); @@ -797,10 +797,10 @@ int test7(struct Options options) outdisconnectProperties.max_count = 10; outdisconnectProperties.array = out_disconnect_props; - one.identifier = SESSION_EXPIRY_INTERVAL; + one.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL; one.value.integer4 = 45; rc = MQTTProperties_add(&disconnectProperties, &one); - reasonCode = MQTTV5_TOPIC_ALIAS_INVALID; // (148) test signed char to unsigned char conversion. + reasonCode = MQTTREASONCODE_TOPIC_ALIAS_INVALID; // (148) test signed char to unsigned char conversion. rc = MQTTV5Serialize_disconnect(buf, buflen, reasonCode, &disconnectProperties); assert("good rc from serialize disconnect", rc > 0, "rc was %d\n", rc); @@ -834,7 +834,7 @@ int test8(struct Options options) int count = TOPIC_COUNT; unsigned char reasonCodes[TOPIC_COUNT] = { 2, - MQTTV5_QOS_NOT_SUPPORTED // (155) test signed char to unsigned char conversion. + MQTTREASONCODE_QOS_NOT_SUPPORTED // (155) test signed char to unsigned char conversion. }; unsigned short msgid2 = 2223; @@ -852,7 +852,7 @@ int test8(struct Options options) outProperties.array = out_props; MQTTProperty one; - one.identifier = USER_PROPERTY; + one.identifier = MQTTPROPERTY_CODE_USER_PROPERTY; one.value.string_pair.key.data = "user property name"; one.value.string_pair.key.len = strlen(one.value.string_pair.key.data); one.value.string_pair.val.data = "user property value"; @@ -893,7 +893,7 @@ int test9(struct Options options) int rc = 0; unsigned char buf[100]; int buflen = sizeof(buf); - unsigned char reasonCode = MQTTV5_BAD_AUTHENTICATION_METHOD; // (140) test signed char to unsigned char conversion. + unsigned char reasonCode = MQTTREASONCODE_BAD_AUTHENTICATION_METHOD; // (140) test signed char to unsigned char conversion. unsigned char reasonCode2 = 44; MQTTProperties properties = MQTTProperties_initializer; @@ -907,7 +907,7 @@ int test9(struct Options options) outProperties.array = out_props; MQTTProperty one; - one.identifier = USER_PROPERTY; + one.identifier = MQTTPROPERTY_CODE_USER_PROPERTY; one.value.string_pair.key.data = "user property name"; one.value.string_pair.key.len = strlen(one.value.string_pair.key.data); one.value.string_pair.val.data = "user property value"; diff --git a/MQTTPacket/test/test3.c b/MQTTPacket/test/test3.c index 7479ad02..fb7ac635 100644 --- a/MQTTPacket/test/test3.c +++ b/MQTTPacket/test/test3.c @@ -274,12 +274,12 @@ int test1(struct Options options) properties.max_count = 10; properties.array = props; - one.identifier = SESSION_EXPIRY_INTERVAL; + one.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL; one.value.integer4 = 45; rc = MQTTProperties_add(&properties, &one); assert("add properties rc should be 0", rc == 0, "rc was different %d\n", rc); - one.identifier = USER_PROPERTY; + one.identifier = MQTTPROPERTY_CODE_USER_PROPERTY; one.value.string_pair.key.data = "user property name"; one.value.string_pair.key.len = strlen(one.value.string_pair.key.data); one.value.string_pair.val.data = "user property value"; @@ -308,7 +308,7 @@ int test1(struct Options options) /* subscribe */ properties.length = properties.count = 0; /* remove existing properties */ topicString.cstring = test_topic; - struct subscribeOptions opts = {0, 0, 0}; + MQTTSubscribe_options opts = {0, 0, 0}; opts.noLocal = 0; opts.retainAsPublished = 1; opts.retainHandling = 2; @@ -336,7 +336,7 @@ int test1(struct Options options) } properties.length = properties.count = 0; /* remove existing properties */ - one.identifier = PAYLOAD_FORMAT_INDICATOR; + one.identifier = MQTTPROPERTY_CODE_PAYLOAD_FORMAT_INDICATOR; one.value.byte = 3; rc = MQTTProperties_add(&properties, &one);