Update documentation #503

This commit is contained in:
Ian Craggs 2018-08-01 20:01:12 +01:00
parent 803ef6e22e
commit 992af7ac02
24 changed files with 5451 additions and 8800 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1585,7 +1585,7 @@ static void nextOrClose(MQTTAsyncs* m, int rc, char* message)
{
MQTTAsync_queuedCommand* conn;
MQTTAsync_closeOnly(m->c, SUCCESS, NULL);
MQTTAsync_closeOnly(m->c, MQTTREASONCODE_SUCCESS, NULL);
/* put the connect command back to the head of the command queue, using the next serverURI */
conn = malloc(sizeof(MQTTAsync_queuedCommand));
memset(conn, '\0', sizeof(MQTTAsync_queuedCommand));
@ -1608,7 +1608,7 @@ static void nextOrClose(MQTTAsyncs* m, int rc, char* message)
}
else
{
MQTTAsync_closeSession(m->c, SUCCESS, NULL);
MQTTAsync_closeSession(m->c, MQTTREASONCODE_SUCCESS, NULL);
if (m->connect.onFailure)
{
MQTTAsync_failureData data;
@ -1879,7 +1879,7 @@ void MQTTAsync_destroy(MQTTAsync* handle)
if (m == NULL)
goto exit;
MQTTAsync_closeSession(m->c, SUCCESS, NULL);
MQTTAsync_closeSession(m->c, MQTTREASONCODE_SUCCESS, NULL);
MQTTAsync_removeResponsesAndCommands(m);
ListFree(m->responses);
@ -2046,7 +2046,7 @@ static thread_return_type WINAPI MQTTAsync_receiveThread(void* n)
else if (m->c->connect_state != NOT_IN_PROGRESS)
nextOrClose(m, rc, "socket error");
else /* calling disconnect_internal won't have any effect if we're already disconnected */
MQTTAsync_closeOnly(m->c, SUCCESS, NULL);
MQTTAsync_closeOnly(m->c, MQTTREASONCODE_SUCCESS, NULL);
}
else
{
@ -2128,9 +2128,9 @@ static thread_return_type WINAPI MQTTAsync_receiveThread(void* n)
}
if (m->c->MQTTVersion >= MQTTVERSION_5)
{
if (MQTTProperties_hasProperty(&connack->properties, RECEIVE_MAXIMUM))
if (MQTTProperties_hasProperty(&connack->properties, MQTTPROPERTY_CODE_RECEIVE_MAXIMUM))
{
int recv_max = MQTTProperties_getNumericValue(&connack->properties, RECEIVE_MAXIMUM);
int recv_max = MQTTProperties_getNumericValue(&connack->properties, MQTTPROPERTY_CODE_RECEIVE_MAXIMUM);
if (m->c->maxInflightMessages > recv_max)
m->c->maxInflightMessages = recv_max;
}
@ -2161,7 +2161,7 @@ static thread_return_type WINAPI MQTTAsync_receiveThread(void* n)
*/
if (m->c->MQTTVersion >= MQTTVERSION_5)
{
if (sub->qoss->count == 1 && *(int*)(sub->qoss->first->content) >= UNSPECIFIED_ERROR)
if (sub->qoss->count == 1 && *(int*)(sub->qoss->first->content) >= MQTTREASONCODE_UNSPECIFIED_ERROR)
{
if (command->command.onFailure5)
{
@ -2930,9 +2930,9 @@ int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions* options)
*m->connectProps = initialized;
*m->connectProps = MQTTProperties_copy(options->connectProperties);
if (MQTTProperties_hasProperty(options->connectProperties, SESSION_EXPIRY_INTERVAL))
if (MQTTProperties_hasProperty(options->connectProperties, MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL))
m->c->sessionExpiry = MQTTProperties_getNumericValue(options->connectProperties,
SESSION_EXPIRY_INTERVAL);
MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL);
}
if (options->willProperties)
@ -3143,8 +3143,8 @@ int MQTTAsync_subscribeMany(MQTTAsync handle, int count, char* const* topic, int
rc = MQTTASYNC_NO_MORE_MSGIDS;
goto exit;
}
if (m->c->MQTTVersion >= MQTTVERSION_5 && count > 1 && (count != response->subscribe_options_count
&& response->subscribe_options_count != 0))
if (m->c->MQTTVersion >= MQTTVERSION_5 && count > 1 && (count != response->subscribeOptionsCount
&& response->subscribeOptionsCount != 0))
{
rc = MQTTASYNC_BAD_MQTT_OPTIONS;
goto exit;
@ -3166,11 +3166,11 @@ int MQTTAsync_subscribeMany(MQTTAsync handle, int count, char* const* topic, int
if (m->c->MQTTVersion >= MQTTVERSION_5)
{
sub->command.properties = MQTTProperties_copy(&response->properties);
sub->command.details.sub.opts = response->subscribe_options;
sub->command.details.sub.opts = response->subscribeOptions;
if (count > 1)
{
sub->command.details.sub.optlist = malloc(sizeof(MQTTSubscribe_options) * count);
if (response->subscribe_options_count == 0)
if (response->subscribeOptionsCount == 0)
{
MQTTSubscribe_options initialized = MQTTSubscribe_options_initializer;
for (i = 0; i < count; ++i)
@ -3179,7 +3179,7 @@ int MQTTAsync_subscribeMany(MQTTAsync handle, int count, char* const* topic, int
else
{
for (i = 0; i < count; ++i)
sub->command.details.sub.optlist[i] = response->subscribe_options_list[i];
sub->command.details.sub.optlist[i] = response->subscribeOptionsList[i];
}
}
}
@ -3642,7 +3642,7 @@ static MQTTPacket* MQTTAsync_cycle(int* sock, unsigned long timeout, int* rc)
}
if (!m)
Log(LOG_ERROR, -1, "PUBCOMP, PUBACK or PUBREC received for no client, msgid %d", msgid);
if (m && (pack->header.bits.type != PUBREC || ack.rc >= UNSPECIFIED_ERROR))
if (m && (pack->header.bits.type != PUBREC || ack.rc >= MQTTREASONCODE_UNSPECIFIED_ERROR))
{
ListElement* current = NULL;
@ -3672,7 +3672,7 @@ static MQTTPacket* MQTTAsync_cycle(int* sock, unsigned long timeout, int* rc)
Log(TRACE_MIN, -1, "Calling publish success for client %s", m->c->clientID);
(*(command->command.onSuccess))(command->command.context, &data);
}
else if (command->command.onSuccess5 && ack.rc < UNSPECIFIED_ERROR)
else if (command->command.onSuccess5 && ack.rc < MQTTREASONCODE_UNSPECIFIED_ERROR)
{
MQTTAsync_successData5 data = MQTTAsync_successData5_initializer;
@ -3686,7 +3686,7 @@ static MQTTPacket* MQTTAsync_cycle(int* sock, unsigned long timeout, int* rc)
Log(TRACE_MIN, -1, "Calling publish success for client %s", m->c->clientID);
(*(command->command.onSuccess5))(command->command.context, &data);
}
else if (command->command.onFailure5 && ack.rc >= UNSPECIFIED_ERROR)
else if (command->command.onFailure5 && ack.rc >= MQTTREASONCODE_UNSPECIFIED_ERROR)
{
MQTTAsync_failureData5 data = MQTTAsync_failureData5_initializer;

View File

@ -419,11 +419,6 @@ typedef void MQTTAsync_disconnected(void* context, MQTTProperties* properties,
*/
DLLExport int MQTTAsync_setDisconnected(MQTTAsync handle, void* context, MQTTAsync_disconnected* co);
typedef void MQTTAsync_published(void* context, int msgid, int packet_type, MQTTProperties* properties,
enum MQTTReasonCodes reasonCode);
DLLExport int MQTTAsync_setPublished(MQTTAsync handle, void* context, MQTTAsync_published* co);
/** The data returned on completion of an unsuccessful API call in the response callback onFailure. */
typedef struct
@ -458,7 +453,7 @@ typedef struct
int packet_type;
} MQTTAsync_failureData5;
#define MQTTAsync_failureData5_initializer {{'M', 'Q', 'F', 'D'}, 0, 0, SUCCESS, MQTTProperties_initializer, 0, NULL}
#define MQTTAsync_failureData5_initializer {{'M', 'Q', 'F', 'D'}, 0, 0, MQTTREASONCODE_SUCCESS, MQTTProperties_initializer, 0, NULL}
/** The data returned on completion of a successful API call in the response callback onSuccess. */
typedef struct
@ -492,48 +487,44 @@ typedef struct
/** The data returned on completion of a successful API call in the response callback onSuccess. */
typedef struct
{
/** The eyecatcher for this structure. Will be MQSD. */
char struct_id[4];
/** The version number of this structure. Will be 0 */
int struct_version;
char struct_id[4]; /**< The eyecatcher for this structure. Will be MQSD. */
int struct_version; /**< The version number of this structure. Will be 0 */
/** A token identifying the successful request. Can be used to refer to the request later. */
MQTTAsync_token token;
/** MQTT V5 reason code returned */
enum MQTTReasonCodes reasonCode;
/** MQTT V5 properties returned, if any */
MQTTProperties properties;
enum MQTTReasonCodes reasonCode; /**< MQTT V5 reason code returned */
MQTTProperties properties; /**< MQTT V5 properties returned, if any */
/** A union of the different values that can be returned for subscribe, unsubscribe and publish. */
union
{
/** For subscribeMany, the list of reasonCodes returned by the server. */
struct
{
int reasonCodeCount;
enum MQTTReasonCodes* reasonCodes;
int reasonCodeCount; /**< the number of reason codes in the reasonCodes array */
enum MQTTReasonCodes* reasonCodes; /**< an array of reasonCodes */
} sub;
/** For publish, the message being sent to the server. */
struct
{
MQTTAsync_message message;
char* destinationName;
MQTTAsync_message message; /**< the message being sent to the server */
char* destinationName; /**< the topic destination for the message */
} pub;
/* For connect, the server connected to, MQTT version used, and sessionPresent flag */
struct
{
char* serverURI;
int MQTTVersion;
int sessionPresent;
char* serverURI; /**< the connection string of the server */
int MQTTVersion; /**< the version of MQTT being used */
int sessionPresent; /**< the session present flag returned from the server */
} connect;
/** For unsubscribeMany, the list of reasonCodes returned by the server. */
struct
{
int reasonCodeCount;
enum MQTTReasonCodes* reasonCodes;
int reasonCodeCount; /**< the number of reason codes in the reasonCodes array */
enum MQTTReasonCodes* reasonCodes; /**< an array of reasonCodes */
} unsub;
} alt;
} MQTTAsync_successData5;
#define MQTTAsync_successData5_initializer {{'M', 'Q', 'S', 'D'}, 0, 0, SUCCESS, MQTTProperties_initializer}
#define MQTTAsync_successData5_initializer {{'M', 'Q', 'S', 'D'}, 0, 0, MQTTREASONCODE_SUCCESS, MQTTProperties_initializer}
/**
* This is a callback function. The client application
@ -547,9 +538,19 @@ typedef struct
*/
typedef void MQTTAsync_onSuccess(void* context, MQTTAsync_successData* response);
/**
* This is a callback function, the MQTT V5 version of ::MQTTAsync_onSuccess.
* The client application
* must provide an implementation of this function to enable asynchronous
* notification of the successful completion of an API call. The function is
* registered with the client library by passing it as an argument in
* ::MQTTAsync_responseOptions.
* @param context A pointer to the <i>context</i> value originally passed to
* ::MQTTAsync_responseOptions, which contains any application-specific context.
* @param response Any success data associated with the API completion.
*/
typedef void MQTTAsync_onSuccess5(void* context, MQTTAsync_successData5* response);
/**
* This is a callback function. The client application
* must provide an implementation of this function to enable asynchronous
@ -558,10 +559,20 @@ typedef void MQTTAsync_onSuccess5(void* context, MQTTAsync_successData5* respons
* ::MQTTAsync_responseOptions.
* @param context A pointer to the <i>context</i> value originally passed to
* ::MQTTAsync_responseOptions, which contains any application-specific context.
* @param response Any failure data associated with the API completion.
* @param response Failure data associated with the API completion.
*/
typedef void MQTTAsync_onFailure(void* context, MQTTAsync_failureData* response);
/**
* This is a callback function, the MQTT V5 version of ::MQTTAsync_onFailure.
* The application must provide an implementation of this function to enable asynchronous
* notification of the unsuccessful completion of an API call. The function is
* registered with the client library by passing it as an argument in
* ::MQTTAsync_responseOptions.
* @param context A pointer to the <i>context</i> value originally passed to
* ::MQTTAsync_responseOptions, which contains any application-specific context.
* @param response Failure data associated with the API completion.
*/
typedef void MQTTAsync_onFailure5(void* context, MQTTAsync_failureData5* response);
typedef struct MQTTAsync_responseOptions
@ -611,9 +622,19 @@ typedef struct MQTTAsync_responseOptions
* MQTT V5 input properties
*/
MQTTProperties properties;
MQTTSubscribe_options subscribe_options;
int subscribe_options_count;
MQTTSubscribe_options* subscribe_options_list;
/*
* MQTT V5 subscribe options, when used with subscribe only.
*/
MQTTSubscribe_options subscribeOptions;
/*
* MQTT V5 subscribe option count, when used with subscribeMany only.
* The number of entries in the subscribe_options_list array.
*/
int subscribeOptionsCount;
/*
* MQTT V5 subscribe option array, when used with subscribeMany only.
*/
MQTTSubscribe_options* subscribeOptionsList;
} MQTTAsync_responseOptions;
#define MQTTAsync_responseOptions_initializer { {'M', 'Q', 'T', 'R'}, 1, NULL, NULL, 0, 0, NULL, NULL, MQTTProperties_initializer, MQTTSubscribe_options_initializer, 0, NULL}
@ -842,7 +863,7 @@ typedef struct
* MQTTAsync_message.qos and @ref qos).
*/
int qos;
/** The LWT payload in binary form. This is only checked and used if the message option is NULL */
/** The LWT payload in binary form. This is only checked and used if the message option is NULL */
struct
{
int len; /**< binary payload length */
@ -1178,7 +1199,7 @@ typedef struct
MQTTAsync_onFailure5* onFailure5;
} MQTTAsync_disconnectOptions;
#define MQTTAsync_disconnectOptions_initializer { {'M', 'Q', 'T', 'D'}, 1, 0, NULL, NULL, NULL, MQTTProperties_initializer, SUCCESS }
#define MQTTAsync_disconnectOptions_initializer { {'M', 'Q', 'T', 'D'}, 1, 0, NULL, NULL, NULL, MQTTProperties_initializer, MQTTREASONCODE_SUCCESS }
/**
@ -1449,9 +1470,10 @@ typedef struct
DLLExport MQTTAsync_nameValue* MQTTAsync_getVersionInfo(void);
/**
* Returns a pointer to the string representation of the error or NULL.
*
* Returns a pointer to a string representation of the error code, or NULL.
* Do not free after use. Returns NULL if the error code is unknown.
* @param code the MQTTASYNC_ return code.
* @return a static string representation of the error code.
*/
DLLExport const char* MQTTAsync_strerror(int code);

View File

@ -849,7 +849,7 @@ static thread_return_type WINAPI MQTTClient_run(void* n)
dp->properties = malloc(sizeof(MQTTProperties));
*(dp->properties) = disc->properties;
free(disc);
MQTTClient_disconnect1(m, 10, 0, 1, SUCCESS, NULL);
MQTTClient_disconnect1(m, 10, 0, 1, MQTTREASONCODE_SUCCESS, NULL);
Log(TRACE_MIN, -1, "Calling disconnected for client %s", m->c->clientID);
Thread_start(call_disconnected, dp);
}
@ -1302,7 +1302,7 @@ exit:
}
}
else
MQTTClient_disconnect1(handle, 0, 0, (MQTTVersion == 3), SUCCESS, NULL); /* don't want to call connection lost */
MQTTClient_disconnect1(handle, 0, 0, (MQTTVersion == 3), MQTTREASONCODE_SUCCESS, NULL); /* don't want to call connection lost */
resp.reasonCode = rc;
FUNC_EXIT_RC(resp.reasonCode);
@ -1608,15 +1608,15 @@ MQTTResponse MQTTClient_connect5(MQTTClient handle, MQTTClient_connectOptions* o
}
#endif
rc = MQTTClient_connectURI(handle, options, serverURI, connectProperties, willProperties);
if (rc.reasonCode == SUCCESS)
if (rc.reasonCode == MQTTREASONCODE_SUCCESS)
break;
}
}
if (rc.reasonCode == SUCCESS)
if (rc.reasonCode == MQTTREASONCODE_SUCCESS)
{
if (rc.properties && MQTTProperties_hasProperty(rc.properties, RECEIVE_MAXIMUM))
if (rc.properties && MQTTProperties_hasProperty(rc.properties, MQTTPROPERTY_CODE_RECEIVE_MAXIMUM))
{
int recv_max = MQTTProperties_getNumericValue(rc.properties, RECEIVE_MAXIMUM);
int recv_max = MQTTProperties_getNumericValue(rc.properties, MQTTPROPERTY_CODE_RECEIVE_MAXIMUM);
if (m->c->maxInflightMessages > recv_max)
m->c->maxInflightMessages = recv_max;
}
@ -1696,7 +1696,7 @@ exit:
*/
static int MQTTClient_disconnect_internal(MQTTClient handle, int timeout)
{
return MQTTClient_disconnect1(handle, timeout, 1, 1, SUCCESS, NULL);
return MQTTClient_disconnect1(handle, timeout, 1, 1, MQTTREASONCODE_SUCCESS, NULL);
}
@ -1714,7 +1714,7 @@ int MQTTClient_disconnect(MQTTClient handle, int timeout)
int rc = 0;
Thread_lock_mutex(mqttclient_mutex);
rc = MQTTClient_disconnect1(handle, timeout, 0, 1, SUCCESS, NULL);
rc = MQTTClient_disconnect1(handle, timeout, 0, 1, MQTTREASONCODE_SUCCESS, NULL);
Thread_unlock_mutex(mqttclient_mutex);
return rc;
}
@ -2300,7 +2300,7 @@ static MQTTPacket* MQTTClient_cycle(int* sock, unsigned long timeout, int* rc)
{
Pubrec* pubrec = (Pubrec*)pack;
if (m && m->c->MQTTVersion >= MQTTVERSION_5 && m->published && pubrec->rc >= UNSPECIFIED_ERROR)
if (m && m->c->MQTTVersion >= MQTTVERSION_5 && m->published && pubrec->rc >= MQTTREASONCODE_UNSPECIFIED_ERROR)
{
Log(TRACE_MIN, -1, "Calling published for client %s, msgid %d", m->c->clientID, ack.msgId);
(*(m->published))(m->published_context, pubrec->msgId, pack->header.bits.type,

View File

@ -421,35 +421,56 @@ DLLExport int MQTTClient_setCallbacks(MQTTClient handle, void* context, MQTTClie
/**
* This is a callback function, which will be called when the client
* library successfully connects. This is superfluous when the connection
* is made in response to a MQTTAsync_connect call, because the onSuccess
* callback can be used. It is intended for use when automatic reconnect
* is enabled, so that when a reconnection attempt succeeds in the background,
* the application is notified and can take any required actions.
* This is a callback function, which will be called when the a disconnect
* packet is received from the server. This applies to MQTT V5 and above only.
* @param context A pointer to the <i>context</i> value originally passed to
* MQTTAsync_setCallbacks(), which contains any application-specific context.
* @param cause The reason for the disconnection.
* ::MQTTAsync_setDisconnected(), which contains any application-specific context.
* @param properties The MQTT V5 properties received with the disconnect, if any.
* @param reasonCode The MQTT V5 reason code received with the disconnect.
* Currently, <i>cause</i> is always set to NULL.
*/
typedef void MQTTClient_disconnected(void* context, MQTTProperties* properties,
enum MQTTReasonCodes reasonCode);
/**
* Sets the MQTTClient_disconnected() callback function for a client.
* Sets the MQTTClient_disconnected() callback function for a client. This will be called
* if a disconnect packet is received from the server. Only valid for MQTT V5 and above.
* @param handle A valid client handle from a successful call to
* MQTTAsync_create().
* MQTTClient_create().
* @param context A pointer to any application-specific context. The
* the <i>context</i> pointer is passed to each of the callback functions to
* provide access to the context information in the callback.
* @param co A pointer to an MQTTAsync_connected() callback
* @param co A pointer to an MQTTClient_disconnected() callback
* function. NULL removes the callback setting.
* @return ::MQTTASYNC_SUCCESS if the callbacks were correctly set,
* ::MQTTASYNC_FAILURE if an error occurred.
* @return ::MQTTCLIENT_SUCCESS if the callbacks were correctly set,
* ::MQTTCLIENT_FAILURE if an error occurred.
*/
DLLExport int MQTTClient_setDisconnected(MQTTClient handle, void* context, MQTTClient_disconnected* co);
typedef void MQTTClient_published(void* context, int msgid, int packet_type, MQTTProperties* properties,
/**
* This is a callback function, the MQTT V5 version of MQTTClient_deliveryComplete().
* The client application
* must provide an implementation of this function to enable asynchronous
* notification of the completed delivery of messages.
* It is called by the client library after the client application has
* published a message to the server. It indicates that the necessary
* handshaking and acknowledgements for the requested quality of service (see
* MQTTClient_message.qos) have been completed. This function is executed on a
* separate thread to the one on which the client application is running.
* <b>Note:</b> It is not called when messages are published at QoS0.
* @param context A pointer to the <i>context</i> value originally passed to
* MQTTClient_setCallbacks(), which contains any application-specific context.
* @param dt The ::MQTTClient_deliveryToken associated with
* the published message. Applications can check that all messages have been
* correctly published by matching the delivery tokens returned from calls to
* MQTTClient_publish() and MQTTClient_publishMessage() with the tokens passed
* to this callback.
* @param packet_type the last received packet type for this completion. For QoS 1
* always PUBACK. For QoS 2 could be PUBREC or PUBCOMP.
* @param properties the MQTT V5 properties returned with the last packet from the server
* @param reasonCode the reason code returned from the server
*/
typedef void MQTTClient_published(void* context, int dt, int packet_type, MQTTProperties* properties,
enum MQTTReasonCodes reasonCode);
DLLExport int MQTTClient_setPublished(MQTTClient handle, void* context, MQTTClient_published* co);
@ -511,6 +532,50 @@ typedef struct
#define MQTTClient_createOptions_initializer { {'M', 'Q', 'C', 'O'}, MQTTVERSION_DEFAULT }
/**
* A version of :MQTTClient_create() with additional options.
* This function creates an MQTT client ready for connection to the
* specified server and using the specified persistent storage (see
* MQTTClient_persistence). See also MQTTClient_destroy().
* @param handle A pointer to an ::MQTTClient handle. The handle is
* populated with a valid client reference following a successful return from
* this function.
* @param serverURI A null-terminated string specifying the server to
* which the client will connect. It takes the form <i>protocol://host:port</i>.
* Currently, <i>protocol</i> must be <i>tcp</i> or <i>ssl</i>.
* For <i>host</i>, you can
* specify either an IP address or a host name. For instance, to connect to
* a server running on the local machines with the default MQTT port, specify
* <i>tcp://localhost:1883</i>.
* @param clientId The client identifier passed to the server when the
* client connects to it. It is a null-terminated UTF-8 encoded string.
* @param persistence_type The type of persistence to be used by the client:
* <br>
* ::MQTTCLIENT_PERSISTENCE_NONE: Use in-memory persistence. If the device or
* system on which the client is running fails or is switched off, the current
* state of any in-flight messages is lost and some messages may not be
* delivered even at QoS1 and QoS2.
* <br>
* ::MQTTCLIENT_PERSISTENCE_DEFAULT: Use the default (file system-based)
* persistence mechanism. Status about in-flight messages is held in persistent
* storage and provides some protection against message loss in the case of
* unexpected failure.
* <br>
* ::MQTTCLIENT_PERSISTENCE_USER: Use an application-specific persistence
* implementation. Using this type of persistence gives control of the
* persistence mechanism to the application. The application has to implement
* the MQTTClient_persistence interface.
* @param persistence_context If the application uses
* ::MQTTCLIENT_PERSISTENCE_NONE persistence, this argument is unused and should
* be set to NULL. For ::MQTTCLIENT_PERSISTENCE_DEFAULT persistence, it
* should be set to the location of the persistence directory (if set
* to NULL, the persistence directory used is the working directory).
* Applications that use ::MQTTCLIENT_PERSISTENCE_USER persistence set this
* argument to point to a valid MQTTClient_persistence structure.
* @param options additional options for the create.
* @return ::MQTTCLIENT_SUCCESS if the client is successfully created, otherwise
* an error code is returned.
*/
DLLExport int MQTTClient_createWithOptions(MQTTClient* handle, const char* serverURI, const char* clientId,
int persistence_type, void* persistence_context, MQTTClient_createOptions* options);
@ -550,7 +615,7 @@ typedef struct
/** The LWT payload in binary form. This is only checked and used if the message option is NULL */
struct
{
int len; /**< binary payload length */
int len; /**< binary payload length */
const void* data; /**< binary payload data */
} payload;
} MQTTClient_willOptions;
@ -839,7 +904,7 @@ typedef struct MQTTResponse
MQTTProperties* properties; /* optional */
} MQTTResponse;
#define MQTTResponse_initializer {1, SUCCESS, 0, NULL, NULL}
#define MQTTResponse_initializer {1, MQTTREASONCODE_SUCCESS, 0, NULL, NULL}
DLLExport void MQTTResponse_free(MQTTResponse response);

View File

@ -487,7 +487,7 @@ int MQTTPacket_send_disconnect(Clients* client, enum MQTTReasonCodes reason, MQT
if (client->MQTTVersion >= 5)
{
if (props || reason != SUCCESS)
if (props || reason != MQTTREASONCODE_SUCCESS)
{
size_t buflen = 1 + ((props == NULL) ? 0 : MQTTProperties_len(props));
char *buf = malloc(buflen), *ptr = NULL;
@ -746,7 +746,7 @@ void* MQTTPacket_ack(int MQTTVersion, unsigned char aHeader, char* data, size_t
{
MQTTProperties props = MQTTProperties_initializer;
pack->rc = SUCCESS;
pack->rc = MQTTREASONCODE_SUCCESS;
pack->properties = props;
if (datalen > 2)

View File

@ -27,37 +27,37 @@
static struct nameToType
{
enum PropertyNames name;
enum PropertyTypes type;
enum MQTTPropertyCodes name;
enum MQTTPropertyTypes type;
} namesToTypes[] =
{
{PAYLOAD_FORMAT_INDICATOR, PROPERTY_TYPE_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, PROPERTY_TYPE_BYTE},
{WILL_DELAY_INTERVAL, FOUR_BYTE_INTEGER},
{REQUEST_RESPONSE_INFORMATION, PROPERTY_TYPE_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, PROPERTY_TYPE_BYTE},
{RETAIN_AVAILABLE, PROPERTY_TYPE_BYTE},
{USER_PROPERTY, UTF_8_STRING_PAIR},
{MAXIMUM_PACKET_SIZE, FOUR_BYTE_INTEGER},
{WILDCARD_SUBSCRIPTION_AVAILABLE, PROPERTY_TYPE_BYTE},
{SUBSCRIPTION_IDENTIFIERS_AVAILABLE, PROPERTY_TYPE_BYTE},
{SHARED_SUBSCRIPTION_AVAILABLE, PROPERTY_TYPE_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_IDENTIFIERS_AVAILABLE, MQTTPROPERTY_TYPE_BYTE},
{MQTTPROPERTY_CODE_SHARED_SUBSCRIPTION_AVAILABLE, MQTTPROPERTY_TYPE_BYTE}
};
@ -69,13 +69,13 @@ static char* datadup(const MQTTLenString* str)
}
int MQTTProperty_getType(int identifier)
int MQTTProperty_getType(enum MQTTPropertyCodes value)
{
int i, rc = -1;
for (i = 0; i < ARRAY_SIZE(namesToTypes); ++i)
{
if (namesToTypes[i].name == identifier)
if (namesToTypes[i].name == value)
{
rc = namesToTypes[i].type;
break;
@ -121,24 +121,24 @@ int MQTTProperties_add(MQTTProperties* props, const MQTTProperty* prop)
/* calculate length */
switch (type)
{
case PROPERTY_TYPE_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:
len = MQTTPacket_VBIlen(prop->value.integer4);
break;
case BINARY_DATA:
case UTF_8_ENCODED_STRING:
case UTF_8_STRING_PAIR:
case MQTTPROPERTY_TYPE_BINARY_DATA:
case MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING:
case MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR:
len = 2 + prop->value.data.len;
props->array[props->count-1].value.data.data = datadup(&prop->value.data);
if (type == UTF_8_STRING_PAIR)
if (type == MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR)
{
len += 2 + prop->value.value.len;
props->array[props->count-1].value.value.data = datadup(&prop->value.value);
@ -159,33 +159,33 @@ int MQTTProperty_write(char** pptr, MQTTProperty* prop)
type = -1;
type = MQTTProperty_getType(prop->identifier);
if (type >= PROPERTY_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 PROPERTY_TYPE_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);
*pptr += rc;
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.data);
writeMQTTLenString(pptr, prop->value.value);
rc = prop->value.data.len + prop->value.value.len + 4; /* include length fields */
@ -196,12 +196,6 @@ int MQTTProperty_write(char** pptr, MQTTProperty* prop)
}
/**
* write the supplied properties into a packet buffer
* @param pptr pointer to the buffer - move the pointer as we add data
* @param properties pointer to the property list, can be NULL
* @return whether the write succeeded or not, number of bytes written or < 0
*/
int MQTTProperties_write(char** pptr, const MQTTProperties* properties)
{
int rc = -1;
@ -239,32 +233,32 @@ int MQTTProperty_read(MQTTProperty* prop, char** pptr, char* enddata)
prop->identifier = readChar(pptr);
type = MQTTProperty_getType(prop->identifier);
if (type >= PROPERTY_TYPE_BYTE && type <= UTF_8_STRING_PAIR)
if (type >= MQTTPROPERTY_TYPE_BYTE && type <= MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR)
{
switch (type)
{
case PROPERTY_TYPE_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 UTF_8_STRING_PAIR:
case MQTTPROPERTY_TYPE_BINARY_DATA:
case MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING:
case MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR:
len = MQTTLenStringRead(&prop->value.data, pptr, enddata);
prop->value.data.data = datadup(&prop->value.data);
if (type == UTF_8_STRING_PAIR)
if (type == MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR)
{
len += MQTTLenStringRead(&prop->value.value, pptr, enddata);
prop->value.value.data = datadup(&prop->value.value);
@ -315,40 +309,40 @@ int MQTTProperties_read(MQTTProperties* properties, char** pptr, char* enddata)
}
struct {
enum PropertyNames value;
enum MQTTPropertyCodes value;
const char* name;
} nameToString[] =
{
{PAYLOAD_FORMAT_INDICATOR, "PAYLOAD_FORMAT_INDICATOR"},
{MESSAGE_EXPIRY_INTERVAL, "MESSAGE_EXPIRY_INTERVAL"},
{CONTENT_TYPE, "CONTENT_TYPE"},
{RESPONSE_TOPIC, "RESPONSE_TOPIC"},
{CORRELATION_DATA, "CORRELATION_DATA"},
{SUBSCRIPTION_IDENTIFIER, "SUBSCRIPTION_IDENTIFIER"},
{SESSION_EXPIRY_INTERVAL, "SESSION_EXPIRY_INTERVAL"},
{ASSIGNED_CLIENT_IDENTIFER, "ASSIGNED_CLIENT_IDENTIFER"},
{SERVER_KEEP_ALIVE, "SERVER_KEEP_ALIVE"},
{AUTHENTICATION_METHOD, "AUTHENTICATION_METHOD"},
{AUTHENTICATION_DATA, "AUTHENTICATION_DATA"},
{REQUEST_PROBLEM_INFORMATION, "REQUEST_PROBLEM_INFORMATION"},
{WILL_DELAY_INTERVAL, "WILL_DELAY_INTERVAL"},
{REQUEST_RESPONSE_INFORMATION, "REQUEST_RESPONSE_INFORMATION"},
{RESPONSE_INFORMATION, "RESPONSE_INFORMATION"},
{SERVER_REFERENCE, "SERVER_REFERENCE"},
{REASON_STRING, "REASON_STRING"},
{RECEIVE_MAXIMUM, "RECEIVE_MAXIMUM"},
{TOPIC_ALIAS_MAXIMUM, "TOPIC_ALIAS_MAXIMUM"},
{TOPIC_ALIAS, "TOPIC_ALIAS"},
{MAXIMUM_QOS, "MAXIMUM_QOS"},
{RETAIN_AVAILABLE, "RETAIN_AVAILABLE"},
{USER_PROPERTY, "USER_PROPERTY"},
{MAXIMUM_PACKET_SIZE, "MAXIMUM_PACKET_SIZE"},
{WILDCARD_SUBSCRIPTION_AVAILABLE, "WILDCARD_SUBSCRIPTION_AVAILABLE"},
{SUBSCRIPTION_IDENTIFIERS_AVAILABLE, "SUBSCRIPTION_IDENTIFIERS_AVAILABLE"},
{SHARED_SUBSCRIPTION_AVAILABLE, "SHARED_SUBSCRIPTION_AVAILABLE"}
{MQTTPROPERTY_CODE_PAYLOAD_FORMAT_INDICATOR, "PAYLOAD_FORMAT_INDICATOR"},
{MQTTPROPERTY_CODE_MESSAGE_EXPIRY_INTERVAL, "MESSAGE_EXPIRY_INTERVAL"},
{MQTTPROPERTY_CODE_CONTENT_TYPE, "CONTENT_TYPE"},
{MQTTPROPERTY_CODE_RESPONSE_TOPIC, "RESPONSE_TOPIC"},
{MQTTPROPERTY_CODE_CORRELATION_DATA, "CORRELATION_DATA"},
{MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER, "SUBSCRIPTION_IDENTIFIER"},
{MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL, "SESSION_EXPIRY_INTERVAL"},
{MQTTPROPERTY_CODE_ASSIGNED_CLIENT_IDENTIFER, "ASSIGNED_CLIENT_IDENTIFER"},
{MQTTPROPERTY_CODE_SERVER_KEEP_ALIVE, "SERVER_KEEP_ALIVE"},
{MQTTPROPERTY_CODE_AUTHENTICATION_METHOD, "AUTHENTICATION_METHOD"},
{MQTTPROPERTY_CODE_AUTHENTICATION_DATA, "AUTHENTICATION_DATA"},
{MQTTPROPERTY_CODE_REQUEST_PROBLEM_INFORMATION, "REQUEST_PROBLEM_INFORMATION"},
{MQTTPROPERTY_CODE_WILL_DELAY_INTERVAL, "WILL_DELAY_INTERVAL"},
{MQTTPROPERTY_CODE_REQUEST_RESPONSE_INFORMATION, "REQUEST_RESPONSE_INFORMATION"},
{MQTTPROPERTY_CODE_RESPONSE_INFORMATION, "RESPONSE_INFORMATION"},
{MQTTPROPERTY_CODE_SERVER_REFERENCE, "SERVER_REFERENCE"},
{MQTTPROPERTY_CODE_REASON_STRING, "REASON_STRING"},
{MQTTPROPERTY_CODE_RECEIVE_MAXIMUM, "RECEIVE_MAXIMUM"},
{MQTTPROPERTY_CODE_TOPIC_ALIAS_MAXIMUM, "TOPIC_ALIAS_MAXIMUM"},
{MQTTPROPERTY_CODE_TOPIC_ALIAS, "TOPIC_ALIAS"},
{MQTTPROPERTY_CODE_MAXIMUM_QOS, "MAXIMUM_QOS"},
{MQTTPROPERTY_CODE_RETAIN_AVAILABLE, "RETAIN_AVAILABLE"},
{MQTTPROPERTY_CODE_USER_PROPERTY, "USER_PROPERTY"},
{MQTTPROPERTY_CODE_MAXIMUM_PACKET_SIZE, "MAXIMUM_PACKET_SIZE"},
{MQTTPROPERTY_CODE_WILDCARD_SUBSCRIPTION_AVAILABLE, "WILDCARD_SUBSCRIPTION_AVAILABLE"},
{MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIERS_AVAILABLE, "SUBSCRIPTION_IDENTIFIERS_AVAILABLE"},
{MQTTPROPERTY_CODE_SHARED_SUBSCRIPTION_AVAILABLE, "SHARED_SUBSCRIPTION_AVAILABLE"}
};
const char* MQTTPropertyName(enum PropertyNames value)
const char* MQTTPropertyName(enum MQTTPropertyCodes value)
{
int i = 0;
const char* result = NULL;
@ -379,11 +373,11 @@ DLLExport void MQTTProperties_free(MQTTProperties* props)
switch (type)
{
case BINARY_DATA:
case UTF_8_ENCODED_STRING:
case UTF_8_STRING_PAIR:
case MQTTPROPERTY_TYPE_BINARY_DATA:
case MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING:
case MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR:
free(props->array[i].value.data.data);
if (type == UTF_8_STRING_PAIR)
if (type == MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR)
free(props->array[i].value.value.data);
break;
}
@ -415,7 +409,7 @@ MQTTProperties MQTTProperties_copy(const MQTTProperties* props)
}
int MQTTProperties_hasProperty(MQTTProperties *props, int propid)
int MQTTProperties_hasProperty(MQTTProperties *props, enum MQTTPropertyCodes propid)
{
int i = 0;
int found = 0;
@ -432,7 +426,7 @@ int MQTTProperties_hasProperty(MQTTProperties *props, int propid)
}
int MQTTProperties_propertyCount(MQTTProperties *props, int propid)
int MQTTProperties_propertyCount(MQTTProperties *props, enum MQTTPropertyCodes propid)
{
int i = 0;
int count = 0;
@ -446,7 +440,7 @@ int MQTTProperties_propertyCount(MQTTProperties *props, int propid)
}
int MQTTProperties_getNumericValueAt(MQTTProperties *props, int propid, int index)
int MQTTProperties_getNumericValueAt(MQTTProperties *props, enum MQTTPropertyCodes propid, int index)
{
int i = 0;
int rc = -9999999;
@ -465,14 +459,14 @@ int MQTTProperties_getNumericValueAt(MQTTProperties *props, int propid, int inde
}
switch (MQTTProperty_getType(id))
{
case PROPERTY_TYPE_BYTE:
case MQTTPROPERTY_TYPE_BYTE:
rc = props->array[i].value.byte;
break;
case TWO_BYTE_INTEGER:
case MQTTPROPERTY_TYPE_TWO_BYTE_INTEGER:
rc = props->array[i].value.integer2;
break;
case FOUR_BYTE_INTEGER:
case VARIABLE_BYTE_INTEGER:
case MQTTPROPERTY_TYPE_FOUR_BYTE_INTEGER:
case MQTTPROPERTY_TYPE_VARIABLE_BYTE_INTEGER:
rc = props->array[i].value.integer4;
break;
default:
@ -486,13 +480,13 @@ int MQTTProperties_getNumericValueAt(MQTTProperties *props, int propid, int inde
}
int MQTTProperties_getNumericValue(MQTTProperties *props, int propid)
int MQTTProperties_getNumericValue(MQTTProperties *props, enum MQTTPropertyCodes propid)
{
return MQTTProperties_getNumericValueAt(props, propid, 0);
}
MQTTProperty* MQTTProperties_getPropertyAt(MQTTProperties *props, int propid, int index)
MQTTProperty* MQTTProperties_getPropertyAt(MQTTProperties *props, enum MQTTPropertyCodes propid, int index)
{
int i = 0;
MQTTProperty* result = NULL;
@ -517,7 +511,7 @@ MQTTProperty* MQTTProperties_getPropertyAt(MQTTProperties *props, int propid, in
}
MQTTProperty* MQTTProperties_getProperty(MQTTProperties *props, int propid)
MQTTProperty* MQTTProperties_getProperty(MQTTProperties *props, enum MQTTPropertyCodes propid)
{
return MQTTProperties_getPropertyAt(props, propid, 0);
}

View File

@ -19,34 +19,35 @@
#define MQTT_INVALID_PROPERTY_ID -2
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_IDENTIFIERS_AVAILABLE = 41,
SHARED_SUBSCRIPTION_AVAILABLE = 42
/** The one byte MQTT V5 property indicator */
enum MQTTPropertyCodes {
MQTTPROPERTY_CODE_PAYLOAD_FORMAT_INDICATOR = 1, /**< The value is 1 */
MQTTPROPERTY_CODE_MESSAGE_EXPIRY_INTERVAL = 2, /**< The value is 2 */
MQTTPROPERTY_CODE_CONTENT_TYPE = 3, /**< The value is 3 */
MQTTPROPERTY_CODE_RESPONSE_TOPIC = 8, /**< The value is 8 */
MQTTPROPERTY_CODE_CORRELATION_DATA = 9, /**< The value is 9 */
MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER = 11, /**< The value is 11 */
MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL = 17, /**< The value is 17 */
MQTTPROPERTY_CODE_ASSIGNED_CLIENT_IDENTIFER = 18,/**< The value is 18 */
MQTTPROPERTY_CODE_SERVER_KEEP_ALIVE = 19, /**< The value is 19 */
MQTTPROPERTY_CODE_AUTHENTICATION_METHOD = 21, /**< The value is 21 */
MQTTPROPERTY_CODE_AUTHENTICATION_DATA = 22, /**< The value is 22 */
MQTTPROPERTY_CODE_REQUEST_PROBLEM_INFORMATION = 23,/**< The value is 23 */
MQTTPROPERTY_CODE_WILL_DELAY_INTERVAL = 24, /**< The value is 24 */
MQTTPROPERTY_CODE_REQUEST_RESPONSE_INFORMATION = 25,/**< The value is 25 */
MQTTPROPERTY_CODE_RESPONSE_INFORMATION = 26, /**< The value is 26 */
MQTTPROPERTY_CODE_SERVER_REFERENCE = 28, /**< The value is 28 */
MQTTPROPERTY_CODE_REASON_STRING = 31, /**< The value is 31 */
MQTTPROPERTY_CODE_RECEIVE_MAXIMUM = 33, /**< The value is 33*/
MQTTPROPERTY_CODE_TOPIC_ALIAS_MAXIMUM = 34, /**< The value is 34 */
MQTTPROPERTY_CODE_TOPIC_ALIAS = 35, /**< The value is 35 */
MQTTPROPERTY_CODE_MAXIMUM_QOS = 36, /**< The value is 36 */
MQTTPROPERTY_CODE_RETAIN_AVAILABLE = 37, /**< The value is 37 */
MQTTPROPERTY_CODE_USER_PROPERTY = 38, /**< The value is 38 */
MQTTPROPERTY_CODE_MAXIMUM_PACKET_SIZE = 39, /**< The value is 39 */
MQTTPROPERTY_CODE_WILDCARD_SUBSCRIPTION_AVAILABLE = 40,/**< The value is 40 */
MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIERS_AVAILABLE = 41,/**< The value is 41 */
MQTTPROPERTY_CODE_SHARED_SUBSCRIPTION_AVAILABLE = 42/**< The value is 241 */
};
#if defined(WIN32) || defined(WIN64)
@ -57,73 +58,168 @@ enum PropertyNames {
#define DLLExport __attribute__ ((visibility ("default")))
#endif
DLLExport const char* MQTTPropertyName(enum PropertyNames);
/**
* Returns a printable string description of an MQTT V5 property code.
* @param value an MQTT V5 property code.
* @return the printable string description of the input property code.
* NULL if the code was not found.
*/
DLLExport const char* MQTTPropertyName(enum MQTTPropertyCodes value);
enum PropertyTypes {
PROPERTY_TYPE_BYTE,
TWO_BYTE_INTEGER,
FOUR_BYTE_INTEGER,
VARIABLE_BYTE_INTEGER,
BINARY_DATA,
UTF_8_ENCODED_STRING,
UTF_8_STRING_PAIR
/** The one byte MQTT V5 property type */
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
};
DLLExport int MQTTProperty_getType(int identifier);
/**
* Returns the MQTT V5 type code of an MQTT V5 property.
* @param value an MQTT V5 property code.
* @return the MQTT V5 type code of the input property. -1 if the code was not found.
*/
DLLExport int MQTTProperty_getType(enum MQTTPropertyCodes value);
/**
* The data for a length delimited string
*/
typedef struct
{
int len;
char* data;
int len; /**< the length of the string */
char* data; /**< pointer to the string data */
} MQTTLenString;
/**
* Structure to hold an MQTT version 5 property of any type
*/
typedef struct
{
int identifier; /* mbi */
enum MQTTPropertyCodes identifier; /**< The MQTT V5 property id. A multi-byte integer. */
/** The value of the property, as a union of the different possible types. */
union {
char byte;
short integer2;
int integer4;
char byte; /**< holds the value of a byte property type */
short integer2; /**< holds the value of a 2 byte integer property type */
int integer4; /**< holds the value of a 4 byte integer property type */
struct {
MQTTLenString data;
MQTTLenString value; /* for user properties */
MQTTLenString data; /**< The value of a string property, or the name of a user property. */
MQTTLenString value; /**< The value of a user property. */
};
} value;
} MQTTProperty;
/**
* MQTT version 5 property list
*/
typedef struct MQTTProperties
{
int count; /* number of property entries */
int max_count;
int length; /* mbi: byte length of all properties */
MQTTProperty *array; /* array of properties */
int count; /**< number of property entries in the array */
int max_count; /**< max number of properties that the currently allocated array can store */
int length; /**< mbi: byte length of all properties */
MQTTProperty *array; /**< array of properties */
} MQTTProperties;
#define MQTTProperties_initializer {0, 0, 0, NULL}
/**
* Returns the length of the properties structure when serialized ready for network transmission.
* @param props an MQTT V5 property structure.
* @return the length in bytes of the properties when serialized.
*/
int MQTTProperties_len(MQTTProperties* props);
/**
* Add the property pointer to the property array, no allocation, just a reference
* @param props
* @param prop
* @return whether the write succeeded or not, number of bytes written or < 0
* Add a property pointer to the property array. There is no memory allocation.
* @param props The property list to add the property to.
* @param prop The property to add to the list.
* @return 0 on success, -1 on failure.
*/
DLLExport int MQTTProperties_add(MQTTProperties* props, const MQTTProperty* prop);
/**
* Serialize the given property list to a character buffer, e.g. for writing to the network.
* @param pptr pointer to the buffer - move the pointer as we add data
* @param properties pointer to the property list, can be NULL
* @return whether the write succeeded or not: number of bytes written, or < 0 on failure.
*/
int MQTTProperties_write(char** pptr, const MQTTProperties* properties);
/**
* Reads a property list from a character buffer into an array.
* @param properties pointer to the property list to be filled. Should be initalized but empty.
* @param pptr pointer to the character buffer.
* @param enddata pointer to the end of the character buffer so we don't read beyond.
* @return 1 if the properties were read successfully.
*/
int MQTTProperties_read(MQTTProperties* properties, char** pptr, char* enddata);
/**
* Free all memory allocated to the property list, including any to individual properties.
* @param properties pointer to the property list.
*/
DLLExport void MQTTProperties_free(MQTTProperties* properties);
MQTTProperties MQTTProperties_copy(const MQTTProperties* props);
/**
* Copy the contents of a property list, allocating additional memory if needed.
* @param props pointer to the property list.
* @return the duplicated property list.
*/
DLLExport MQTTProperties MQTTProperties_copy(const MQTTProperties* props);
DLLExport int MQTTProperties_hasProperty(MQTTProperties *props, int propid);
DLLExport int MQTTProperties_propertyCount(MQTTProperties *props, int propid);
DLLExport int MQTTProperties_getNumericValue(MQTTProperties *props, int propid);
DLLExport int MQTTProperties_getNumericValueAt(MQTTProperties *props, int propid, int index);
DLLExport MQTTProperty* MQTTProperties_getProperty(MQTTProperties *props, int propid);
DLLExport MQTTProperty* MQTTProperties_getPropertyAt(MQTTProperties *props, int propid, int index);
/**
* Checks if property list contains a specific property.
* @param props pointer to the property list.
* @param propid the property id to check for.
* @return 1 if found, 0 if not.
*/
DLLExport int MQTTProperties_hasProperty(MQTTProperties *props, enum MQTTPropertyCodes propid);
/**
* Returns the number of instances of a property id. Most properties can exist only once.
* User properties and subscription ids can exist more than once.
* @param props pointer to the property list.
* @param propid the property id to check for.
* @return the number of times found. Can be 0.
*/
DLLExport int MQTTProperties_propertyCount(MQTTProperties *props, enum MQTTPropertyCodes propid);
/**
* Returns the integer value of a specific property. The property given must be a numeric type.
* @param props pointer to the property list.
* @param propid the property id to check for.
* @return the integer value of the property. -9999999 on failure.
*/
DLLExport int MQTTProperties_getNumericValue(MQTTProperties *props, enum MQTTPropertyCodes propid);
/**
* Returns the integer value of a specific property when it's not the only instance.
* The property given must be a numeric type.
* @param props pointer to the property list.
* @param propid the property id to check for.
* @param index the instance number, starting at 0.
* @return the integer value of the property. -9999999 on failure.
*/
DLLExport int MQTTProperties_getNumericValueAt(MQTTProperties *props, enum MQTTPropertyCodes propid, int index);
/**
* Returns a pointer to the property structure for a specific property.
* @param props pointer to the property list.
* @param propid the property id to check for.
* @return the pointer to the property structure if found. NULL if not found.
*/
DLLExport MQTTProperty* MQTTProperties_getProperty(MQTTProperties *props, enum MQTTPropertyCodes propid);
/**
* Returns a pointer to the property structure for a specific property when it's not the only instance.
* @param props pointer to the property list.
* @param propid the property id to check for.
* @param index the instance number, starting at 0.
* @return the pointer to the property structure if found. NULL if not found.
*/
DLLExport MQTTProperty* MQTTProperties_getPropertyAt(MQTTProperties *props, enum MQTTPropertyCodes propid, int index);
#endif /* MQTTPROPERTIES_H */

View File

@ -426,7 +426,7 @@ int MQTTProtocol_handlePubrecs(void* pack, int sock)
}
else
{
if (pubrec->MQTTVersion >= MQTTVERSION_5 && pubrec->rc >= UNSPECIFIED_ERROR)
if (pubrec->MQTTVersion >= MQTTVERSION_5 && pubrec->rc >= MQTTREASONCODE_UNSPECIFIED_ERROR)
{
Log(TRACE_MIN, -1, "Pubrec error %d received for client %s msgid %d, not sending PUBREL",
pubrec->rc, client->clientID, pubrec->msgId);

View File

@ -28,51 +28,51 @@ static struct {
const char* name;
} nameToString[] =
{
{SUCCESS, "SUCCESS"},
{NORMAL_DISCONNECTION, "Normal disconnection"},
{GRANTED_QOS_0, "Granted QoS 0"},
{GRANTED_QOS_1, "Granted QoS 1"},
{GRANTED_QOS_2, "Granted QoS 2"},
{DISCONNECT_WITH_WILL_MESSAGE, "Disconnect with Will Messge"},
{NO_MATCHING_SUBSCRIBERS, "No matching subscribers"},
{NO_SUBSCRIPTION_FOUND, "No subscription found"},
{CONTINUE_AUTHENTICATION, "Continue authentication"},
{RE_AUTHENTICATE, "Re-authenticate"},
{UNSPECIFIED_ERROR, "Unspecified error"},
{MALFORMED_PACKET, "Malformed Packet"},
{PROTOCOL_ERROR, "Protocol error"},
{IMPLEMENTATION_SPECIFIC_ERROR, "Implementation specific error"},
{UNSUPPORTED_PROTOCOL_VERSION, "Unsupported Protocol Version"},
{CLIENT_IDENTIFIER_NOT_VALID, "Client Identifier not valid"},
{BAD_USER_NAME_OR_PASSWORD, "Bad User Name or Password"},
{NOT_AUTHORIZED, "Not authorized"},
{SERVER_UNAVAILABLE, "Server unavailable"},
{SERVER_BUSY, "Server busy"},
{BANNED, "Banned"},
{SERVER_SHUTTING_DOWN, "Server shutting down"},
{BAD_AUTHENTICATION_METHOD, "Bad authentication method"},
{KEEP_ALIVE_TIMEOUT, "Keep Alive timeout"},
{SESSION_TAKEN_OVER, "Session taken over"},
{TOPIC_FILTER_INVALID, "Topic filter invalid"},
{TOPIC_NAME_INVALID, "Topic name invalid"},
{PACKET_IDENTIFIER_IN_USE, "Packet Identifier in use"},
{PACKET_IDENTIFIER_NOT_FOUND, "Packet Identifier not found"},
{RECEIVE_MAXIMUM_EXCEEDED, "Receive Maximum exceeded"},
{TOPIC_ALIAS_INVALID, "Topic Alias invalid"},
{PACKET_TOO_LARGE, "Packet too large"},
{MESSAGE_RATE_TOO_HIGH, "Message rate too high"},
{QUOTA_EXCEEDED, "Quota exceeded"},
{ADMINISTRATIVE_ACTION, "Administrative action"},
{PAYLOAD_FORMAT_INVALID, "Payload format invalid"},
{RETAIN_NOT_SUPPORTED, "Retain not supported"},
{QOS_NOT_SUPPORTED, "QoS not supported"},
{USE_ANOTHER_SERVER, "Use another server"},
{SERVER_MOVED, "Server moved"},
{SHARED_SUBSCRIPTIONS_NOT_SUPPORTED, "Shared subscriptions not supported"},
{CONNECTION_RATE_EXCEEDED, "Connection rate exceeded"},
{MAXIMUM_CONNECT_TIME, "Maximum connect time"},
{SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED, "Subscription Identifiers not supported"},
{WILDCARD_SUBSCRIPTIONS_NOT_SUPPORTED, "Wildcard Subscriptions not supported"}
{MQTTREASONCODE_SUCCESS, "SUCCESS"},
{MQTTREASONCODE_NORMAL_DISCONNECTION, "Normal disconnection"},
{MQTTREASONCODE_GRANTED_QOS_0, "Granted QoS 0"},
{MQTTREASONCODE_GRANTED_QOS_1, "Granted QoS 1"},
{MQTTREASONCODE_GRANTED_QOS_2, "Granted QoS 2"},
{MQTTREASONCODE_DISCONNECT_WITH_WILL_MESSAGE, "Disconnect with Will Messge"},
{MQTTREASONCODE_NO_MATCHING_SUBSCRIBERS, "No matching subscribers"},
{MQTTREASONCODE_NO_SUBSCRIPTION_FOUND, "No subscription found"},
{MQTTREASONCODE_CONTINUE_AUTHENTICATION, "Continue authentication"},
{MQTTREASONCODE_RE_AUTHENTICATE, "Re-authenticate"},
{MQTTREASONCODE_UNSPECIFIED_ERROR, "Unspecified error"},
{MQTTREASONCODE_MALFORMED_PACKET, "Malformed Packet"},
{MQTTREASONCODE_PROTOCOL_ERROR, "Protocol error"},
{MQTTREASONCODE_IMPLEMENTATION_SPECIFIC_ERROR, "Implementation specific error"},
{MQTTREASONCODE_UNSUPPORTED_PROTOCOL_VERSION, "Unsupported Protocol Version"},
{MQTTREASONCODE_CLIENT_IDENTIFIER_NOT_VALID, "Client Identifier not valid"},
{MQTTREASONCODE_BAD_USER_NAME_OR_PASSWORD, "Bad User Name or Password"},
{MQTTREASONCODE_NOT_AUTHORIZED, "Not authorized"},
{MQTTREASONCODE_SERVER_UNAVAILABLE, "Server unavailable"},
{MQTTREASONCODE_SERVER_BUSY, "Server busy"},
{MQTTREASONCODE_BANNED, "Banned"},
{MQTTREASONCODE_SERVER_SHUTTING_DOWN, "Server shutting down"},
{MQTTREASONCODE_BAD_AUTHENTICATION_METHOD, "Bad authentication method"},
{MQTTREASONCODE_KEEP_ALIVE_TIMEOUT, "Keep Alive timeout"},
{MQTTREASONCODE_SESSION_TAKEN_OVER, "Session taken over"},
{MQTTREASONCODE_TOPIC_FILTER_INVALID, "Topic filter invalid"},
{MQTTREASONCODE_TOPIC_NAME_INVALID, "Topic name invalid"},
{MQTTREASONCODE_PACKET_IDENTIFIER_IN_USE, "Packet Identifier in use"},
{MQTTREASONCODE_PACKET_IDENTIFIER_NOT_FOUND, "Packet Identifier not found"},
{MQTTREASONCODE_RECEIVE_MAXIMUM_EXCEEDED, "Receive Maximum exceeded"},
{MQTTREASONCODE_TOPIC_ALIAS_INVALID, "Topic Alias invalid"},
{MQTTREASONCODE_PACKET_TOO_LARGE, "Packet too large"},
{MQTTREASONCODE_MESSAGE_RATE_TOO_HIGH, "Message rate too high"},
{MQTTREASONCODE_QUOTA_EXCEEDED, "Quota exceeded"},
{MQTTREASONCODE_ADMINISTRATIVE_ACTION, "Administrative action"},
{MQTTREASONCODE_PAYLOAD_FORMAT_INVALID, "Payload format invalid"},
{MQTTREASONCODE_RETAIN_NOT_SUPPORTED, "Retain not supported"},
{MQTTREASONCODE_QOS_NOT_SUPPORTED, "QoS not supported"},
{MQTTREASONCODE_USE_ANOTHER_SERVER, "Use another server"},
{MQTTREASONCODE_SERVER_MOVED, "Server moved"},
{MQTTREASONCODE_SHARED_SUBSCRIPTIONS_NOT_SUPPORTED, "Shared subscriptions not supported"},
{MQTTREASONCODE_CONNECTION_RATE_EXCEEDED, "Connection rate exceeded"},
{MQTTREASONCODE_MAXIMUM_CONNECT_TIME, "Maximum connect time"},
{MQTTREASONCODE_SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED, "Subscription Identifiers not supported"},
{MQTTREASONCODE_WILDCARD_SUBSCRIPTIONS_NOT_SUPPORTED, "Wildcard Subscriptions not supported"}
};
const char* MQTTReasonCodeString(enum MQTTReasonCodes value)

View File

@ -17,52 +17,53 @@
#if !defined(MQTTREASONCODES_H)
#define MQTTREASONCODES_H
/** The MQTT V5 one byte reason code */
enum MQTTReasonCodes {
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_SUBSCRIPTIONS_NOT_SUPPORTED = 158,
CONNECTION_RATE_EXCEEDED = 159,
MAXIMUM_CONNECT_TIME = 160,
SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED = 161,
WILDCARD_SUBSCRIPTIONS_NOT_SUPPORTED = 162
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_SUBSCRIPTIONS_NOT_SUPPORTED = 158,
MQTTREASONCODE_CONNECTION_RATE_EXCEEDED = 159,
MQTTREASONCODE_MAXIMUM_CONNECT_TIME = 160,
MQTTREASONCODE_SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED = 161,
MQTTREASONCODE_WILDCARD_SUBSCRIPTIONS_NOT_SUPPORTED = 162
};
#if defined(WIN32) || defined(WIN64)
@ -73,6 +74,12 @@ enum MQTTReasonCodes {
#define DLLExport __attribute__ ((visibility ("default")))
#endif
DLLExport const char* MQTTReasonCodeString(enum MQTTReasonCodes);
/**
* Returns a printable string description of an MQTT V5 reason code.
* @param value an MQTT V5 reason code.
* @return the printable string description of the input reason code.
* NULL if the code was not found.
*/
DLLExport const char* MQTTReasonCodeString(enum MQTTReasonCodes value);
#endif

View File

@ -17,7 +17,7 @@
#if !defined(SUBOPTS_H)
#define SUBOPTS_H
/** The MQTT V5 subscribe options, apart from QoS which existed before V5. */
typedef struct MQTTSubscribe_options
{
/** The eyecatcher for this structure. Must be MQSO. */
@ -25,9 +25,20 @@ typedef struct MQTTSubscribe_options
/** The version number of this structure. Must be 0.
*/
int struct_version;
unsigned char noLocal; /* 0 or 1 */
unsigned char retainAsPublished; /* 0 or 1 */
unsigned char retainHandling; /* 0, 1 or 2 */
/** To not receive our own publications, set to 1.
* 0 is the original MQTT behaviour - all messages matching the subscription are received.
*/
unsigned char noLocal;
/** To keep the retain flag as on the original publish message, set to 1.
* If 0, defaults to the original MQTT behaviour where the retain flag is only set on
* publications sent by a broker if in response to a subscribe request.
*/
unsigned char retainAsPublished;
/** 0 - send retained messages at the time of the subscribe (original MQTT behaviour)
* 1 - send retained messages on subscribe only if the subscription is new
* 2 - do not send retained messages at all
*/
unsigned char retainHandling;
} MQTTSubscribe_options;
#define MQTTSubscribe_options_initializer { {'M', 'Q', 'S', 'O'}, 0, 0, 0, 0 }

View File

@ -338,13 +338,13 @@ int main(int argc, char** argv)
if (opts.message_expiry > 0)
{
property.identifier = MESSAGE_EXPIRY_INTERVAL;
property.identifier = MQTTPROPERTY_CODE_MESSAGE_EXPIRY_INTERVAL;
property.value.integer4 = opts.message_expiry;
MQTTProperties_add(&props, &property);
}
if (opts.user_property.name)
{
property.identifier = USER_PROPERTY;
property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
property.value.data.data = opts.user_property.name;
property.value.data.len = strlen(opts.user_property.name);
property.value.value.data = opts.user_property.value;

View File

@ -193,13 +193,13 @@ int main(int argc, char** argv)
if (opts.message_expiry > 0)
{
property.identifier = MESSAGE_EXPIRY_INTERVAL;
property.identifier = MQTTPROPERTY_CODE_MESSAGE_EXPIRY_INTERVAL;
property.value.integer4 = opts.message_expiry;
MQTTProperties_add(&pub_props, &property);
}
if (opts.user_property.name)
{
property.identifier = USER_PROPERTY;
property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
property.value.data.data = opts.user_property.name;
property.value.data.len = strlen(opts.user_property.name);
property.value.value.data = opts.user_property.value;
@ -280,7 +280,7 @@ exit:
free(buffer);
if (opts.MQTTVersion == MQTTVERSION_5)
rc = MQTTClient_disconnect5(client, 0, SUCCESS, NULL);
rc = MQTTClient_disconnect5(client, 0, MQTTREASONCODE_SUCCESS, NULL);
else
rc = MQTTClient_disconnect(client, 0);

View File

@ -461,24 +461,24 @@ void logProperties(MQTTProperties *props)
switch (MQTTProperty_getType(id))
{
case PROPERTY_TYPE_BYTE:
case MQTTPROPERTY_TYPE_BYTE:
printf(intformat, name, props->array[i].value.byte);
break;
case TWO_BYTE_INTEGER:
case MQTTPROPERTY_TYPE_TWO_BYTE_INTEGER:
printf(intformat, name, props->array[i].value.integer2);
break;
case FOUR_BYTE_INTEGER:
case MQTTPROPERTY_TYPE_FOUR_BYTE_INTEGER:
printf(intformat, name, props->array[i].value.integer4);
break;
case VARIABLE_BYTE_INTEGER:
case MQTTPROPERTY_TYPE_VARIABLE_BYTE_INTEGER:
printf(intformat, name, props->array[i].value.integer4);
break;
case BINARY_DATA:
case UTF_8_ENCODED_STRING:
case MQTTPROPERTY_TYPE_BINARY_DATA:
case MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING:
printf("Property name %s value len %.*s\n", name,
props->array[i].value.data.len, props->array[i].value.data.data);
break;
case UTF_8_STRING_PAIR:
case MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR:
printf("Property name %s key %.*s value %.*s\n", name,
props->array[i].value.data.len, props->array[i].value.data.data,
props->array[i].value.value.len, props->array[i].value.value.data);

View File

@ -307,24 +307,24 @@ void logProperties(MQTTProperties *props)
switch (MQTTProperty_getType(id))
{
case PROPERTY_TYPE_BYTE:
case MQTTPROPERTY_TYPE_BYTE:
MyLog(LOGA_INFO, intformat, name, props->array[i].value.byte);
break;
case TWO_BYTE_INTEGER:
case MQTTPROPERTY_TYPE_TWO_BYTE_INTEGER:
MyLog(LOGA_INFO, intformat, name, props->array[i].value.integer2);
break;
case FOUR_BYTE_INTEGER:
case MQTTPROPERTY_TYPE_FOUR_BYTE_INTEGER:
MyLog(LOGA_INFO, intformat, name, props->array[i].value.integer4);
break;
case VARIABLE_BYTE_INTEGER:
case MQTTPROPERTY_TYPE_VARIABLE_BYTE_INTEGER:
MyLog(LOGA_INFO, intformat, name, props->array[i].value.integer4);
break;
case BINARY_DATA:
case UTF_8_ENCODED_STRING:
case MQTTPROPERTY_TYPE_BINARY_DATA:
case MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING:
MyLog(LOGA_INFO, "Property name value %s %.*s", name,
props->array[i].value.data.len, props->array[i].value.data.data);
break;
case UTF_8_STRING_PAIR:
case MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR:
MyLog(LOGA_INFO, "Property name %s key %.*s value %.*s", name,
props->array[i].value.data.len, props->array[i].value.data.data,
props->array[i].value.value.len, props->array[i].value.value.data);
@ -439,7 +439,7 @@ int test_client_topic_aliases(struct Options options)
pubmsg.retained = 0;
/* a Topic Alias of 0 is not allowed, so we should be disconnected */
property.identifier = TOPIC_ALIAS;
property.identifier = MQTTPROPERTY_CODE_TOPIC_ALIAS;
property.value.integer2 = 0;
MQTTProperties_add(&pubmsg.properties, &property);
@ -459,7 +459,7 @@ int test_client_topic_aliases(struct Options options)
assert("Disconnected should be called", test_topic_aliases_globals.disconnected == 1,
"was %d", test_topic_aliases_globals.disconnected);
property.identifier = SESSION_EXPIRY_INTERVAL;
property.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL;
property.value.integer4 = 30;
MQTTProperties_add(&connect_props, &property);
@ -471,8 +471,8 @@ int test_client_topic_aliases(struct Options options)
if (response.properties)
{
if (MQTTProperties_hasProperty(response.properties, TOPIC_ALIAS_MAXIMUM))
topicAliasMaximum = MQTTProperties_getNumericValue(response.properties, TOPIC_ALIAS_MAXIMUM);
if (MQTTProperties_hasProperty(response.properties, MQTTPROPERTY_CODE_TOPIC_ALIAS_MAXIMUM))
topicAliasMaximum = MQTTProperties_getNumericValue(response.properties, MQTTPROPERTY_CODE_TOPIC_ALIAS_MAXIMUM);
logProperties(response.properties);
MQTTResponse_free(response);
@ -481,11 +481,11 @@ int test_client_topic_aliases(struct Options options)
/* subscribe to a topic */
response = MQTTClient_subscribe5(c, test_topic, 2, NULL, NULL);
assert("Good rc from subscribe", response.reasonCode == GRANTED_QOS_2, "rc was %d", response.reasonCode);
assert("Good rc from subscribe", response.reasonCode == MQTTREASONCODE_GRANTED_QOS_2, "rc was %d", response.reasonCode);
/* then publish to the topic */
MQTTProperties_free(&pubmsg.properties);
property.identifier = TOPIC_ALIAS;
property.identifier = MQTTPROPERTY_CODE_TOPIC_ALIAS;
property.value.integer2 = 1;
MQTTProperties_add(&pubmsg.properties, &property);
@ -520,7 +520,7 @@ int test_client_topic_aliases(struct Options options)
}
assert("1 message should have arrived", messages_arrived == 1, "was %d", messages_arrived);
rc = MQTTClient_disconnect5(c, 1000, SUCCESS, NULL);
rc = MQTTClient_disconnect5(c, 1000, MQTTREASONCODE_SUCCESS, NULL);
/* Reconnect. Topic aliases should be deleted, but not subscription */
opts.cleanstart = 0;
@ -550,7 +550,7 @@ int test_client_topic_aliases(struct Options options)
/* now publish to the topic alias only */
test_topic_aliases_globals.disconnected = 0;
messages_arrived = 0;
property.identifier = TOPIC_ALIAS;
property.identifier = MQTTPROPERTY_CODE_TOPIC_ALIAS;
property.value.integer2 = 1;
MQTTProperties_add(&pubmsg.properties, &property);
response = MQTTClient_publishMessage5(c, "", &pubmsg, &dt);
@ -610,8 +610,8 @@ int test2_messageArrived(void* context, char* topicName, int topicLen, MQTTClien
{
const int props_count = 0;
if (MQTTProperties_hasProperty(&message->properties, TOPIC_ALIAS))
topicAlias = MQTTProperties_getNumericValue(&message->properties, TOPIC_ALIAS);
if (MQTTProperties_hasProperty(&message->properties, MQTTPROPERTY_CODE_TOPIC_ALIAS))
topicAlias = MQTTProperties_getNumericValue(&message->properties, MQTTPROPERTY_CODE_TOPIC_ALIAS);
if (received == 1)
first_topic_alias = topicAlias;
@ -675,7 +675,7 @@ int test_server_topic_aliases(struct Options options)
}
/* Allow at least one server topic alias */
property.identifier = TOPIC_ALIAS_MAXIMUM;
property.identifier = MQTTPROPERTY_CODE_TOPIC_ALIAS_MAXIMUM;
property.value.integer2 = 1;
MQTTProperties_add(&connect_props, &property);
@ -687,8 +687,8 @@ int test_server_topic_aliases(struct Options options)
if (response.properties)
{
if (MQTTProperties_hasProperty(response.properties, TOPIC_ALIAS_MAXIMUM))
topicAliasMaximum = MQTTProperties_getNumericValue(response.properties, TOPIC_ALIAS_MAXIMUM);
if (MQTTProperties_hasProperty(response.properties, MQTTPROPERTY_CODE_TOPIC_ALIAS_MAXIMUM))
topicAliasMaximum = MQTTProperties_getNumericValue(response.properties, MQTTPROPERTY_CODE_TOPIC_ALIAS_MAXIMUM);
logProperties(response.properties);
MQTTResponse_free(response);
@ -696,7 +696,7 @@ int test_server_topic_aliases(struct Options options)
/* subscribe to a topic */
response = MQTTClient_subscribe5(c, test_topic, 2, NULL, NULL);
assert("Good rc from subscribe", response.reasonCode == GRANTED_QOS_2, "rc was %d", response.reasonCode);
assert("Good rc from subscribe", response.reasonCode == MQTTREASONCODE_GRANTED_QOS_2, "rc was %d", response.reasonCode);
messages_arrived = 0;
pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
@ -720,7 +720,7 @@ int test_server_topic_aliases(struct Options options)
}
assert("3 messages should have arrived", messages_arrived == msg_count, "was %d", messages_arrived);
rc = MQTTClient_disconnect5(c, 1000, SUCCESS, NULL);
rc = MQTTClient_disconnect5(c, 1000, MQTTREASONCODE_SUCCESS, NULL);
MQTTProperties_free(&pubmsg.properties);
MQTTProperties_free(&connect_props);
@ -751,11 +751,11 @@ int test_subscription_ids_messageArrived(void* context, char* topicName, int top
{
int subsidcount = 0, i = 0;
subsidcount = MQTTProperties_propertyCount(&message->properties, SUBSCRIPTION_IDENTIFIER);
subsidcount = MQTTProperties_propertyCount(&message->properties, MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER);
for (i = 0; i < subsidcount; ++i)
{
int subsid = MQTTProperties_getNumericValueAt(&message->properties, SUBSCRIPTION_IDENTIFIER, i);
int subsid = MQTTProperties_getNumericValueAt(&message->properties, MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER, i);
assert("Subsid is i+1", subsid == i+1, "subsid is not correct %d\n", subsid);
}
logProperties(&message->properties);
@ -819,8 +819,8 @@ int test_subscription_ids(struct Options options)
if (response.properties)
{
if (MQTTProperties_hasProperty(response.properties, SUBSCRIPTION_IDENTIFIERS_AVAILABLE))
subsids = MQTTProperties_getNumericValue(response.properties, SUBSCRIPTION_IDENTIFIERS_AVAILABLE);
if (MQTTProperties_hasProperty(response.properties, MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIERS_AVAILABLE))
subsids = MQTTProperties_getNumericValue(response.properties, MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIERS_AVAILABLE);
logProperties(response.properties);
MQTTResponse_free(response);
@ -828,17 +828,17 @@ int test_subscription_ids(struct Options options)
assert("Subscription ids must be available", subsids == 1, "subsids is %d", subsids);
/* subscribe to the test topic */
property.identifier = SUBSCRIPTION_IDENTIFIER;
property.identifier = MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER;
property.value.integer4 = 1;
MQTTProperties_add(&subs_props, &property);
response = MQTTClient_subscribe5(c, test_topic, 2, NULL, &subs_props);
assert("Good rc from subscribe", response.reasonCode == GRANTED_QOS_2, "rc was %d", response.reasonCode);
assert("Good rc from subscribe", response.reasonCode == MQTTREASONCODE_GRANTED_QOS_2, "rc was %d", response.reasonCode);
/* now to an overlapping topic */
property.value.integer4 = 2;
subs_props.array[0].value.integer4 = 2;
response = MQTTClient_subscribe5(c, "+", 2, NULL, &subs_props);
assert("Good rc from subscribe", response.reasonCode == GRANTED_QOS_2, "rc was %d", response.reasonCode);
assert("Good rc from subscribe", response.reasonCode == MQTTREASONCODE_GRANTED_QOS_2, "rc was %d", response.reasonCode);
messages_arrived = 0;
pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
@ -860,7 +860,7 @@ int test_subscription_ids(struct Options options)
}
assert("1 message should have arrived", messages_arrived == msg_count, "was %d", messages_arrived);
rc = MQTTClient_disconnect5(c, 1000, SUCCESS, NULL);
rc = MQTTClient_disconnect5(c, 1000, MQTTREASONCODE_SUCCESS, NULL);
MQTTProperties_free(&pubmsg.properties);
MQTTProperties_free(&subs_props);
@ -954,15 +954,15 @@ int test_flow_control(struct Options options)
if (response.properties)
{
if (MQTTProperties_hasProperty(response.properties, RECEIVE_MAXIMUM))
receive_maximum = MQTTProperties_getNumericValue(response.properties, RECEIVE_MAXIMUM);
if (MQTTProperties_hasProperty(response.properties, MQTTPROPERTY_CODE_RECEIVE_MAXIMUM))
receive_maximum = MQTTProperties_getNumericValue(response.properties, MQTTPROPERTY_CODE_RECEIVE_MAXIMUM);
logProperties(response.properties);
MQTTResponse_free(response);
}
response = MQTTClient_subscribe5(c, test_topic, 2, NULL, NULL);
assert("Good rc from subscribe", response.reasonCode == GRANTED_QOS_2, "rc was %d", response.reasonCode);
assert("Good rc from subscribe", response.reasonCode == MQTTREASONCODE_GRANTED_QOS_2, "rc was %d", response.reasonCode);
messages_arrived = 0;
pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
@ -987,7 +987,7 @@ int test_flow_control(struct Options options)
assert("messages should have arrived", messages_arrived == receive_maximum + 2, "was %d", messages_arrived);
assert("should have blocked", blocking_found == 1, "was %d\n", blocking_found);
rc = MQTTClient_disconnect5(c, 1000, SUCCESS, NULL);
rc = MQTTClient_disconnect5(c, 1000, MQTTREASONCODE_SUCCESS, NULL);
exit:
MQTTClient_setTraceCallback(NULL);
@ -1046,21 +1046,21 @@ int test_error_reporting(struct Options options)
if (response.properties)
{
if (MQTTProperties_hasProperty(response.properties, RECEIVE_MAXIMUM))
receive_maximum = MQTTProperties_getNumericValue(response.properties, RECEIVE_MAXIMUM);
if (MQTTProperties_hasProperty(response.properties, MQTTPROPERTY_CODE_RECEIVE_MAXIMUM))
receive_maximum = MQTTProperties_getNumericValue(response.properties, MQTTPROPERTY_CODE_RECEIVE_MAXIMUM);
logProperties(response.properties);
MQTTResponse_free(response);
}
property.identifier = USER_PROPERTY;
property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
property.value.data.data = "unsub user property";
property.value.data.len = strlen(property.value.data.data);
property.value.value.data = "unsub user property value";
property.value.value.len = strlen(property.value.value.data);
MQTTProperties_add(&props, &property);
response = MQTTClient_subscribe5(c, test_topic, 2, NULL, &props);
assert("Good rc from subscribe", response.reasonCode == GRANTED_QOS_2, "rc was %d", response.reasonCode);
assert("Good rc from subscribe", response.reasonCode == MQTTREASONCODE_GRANTED_QOS_2, "rc was %d", response.reasonCode);
assert("Properties should exist", response.properties != NULL, "props was %p", response.properties);
if (response.properties)
{
@ -1077,7 +1077,7 @@ int test_error_reporting(struct Options options)
MQTTResponse_free(response);
}
rc = MQTTClient_disconnect5(c, 1000, SUCCESS, NULL);
rc = MQTTClient_disconnect5(c, 1000, MQTTREASONCODE_SUCCESS, NULL);
exit:
MQTTClient_setTraceCallback(NULL);
@ -1097,7 +1097,7 @@ struct
enum MQTTReasonCodes rc;
} test_qos_1_2_errors_globals =
{
0, -1, SUCCESS
0, -1, MQTTREASONCODE_SUCCESS
};
@ -1177,8 +1177,8 @@ int test_qos_1_2_errors(struct Options options)
if (response.properties)
{
if (MQTTProperties_hasProperty(response.properties, RECEIVE_MAXIMUM))
receive_maximum = MQTTProperties_getNumericValue(response.properties, RECEIVE_MAXIMUM);
if (MQTTProperties_hasProperty(response.properties, MQTTPROPERTY_CODE_RECEIVE_MAXIMUM))
receive_maximum = MQTTProperties_getNumericValue(response.properties, MQTTPROPERTY_CODE_RECEIVE_MAXIMUM);
logProperties(response.properties);
MQTTResponse_free(response);
@ -1189,7 +1189,7 @@ int test_qos_1_2_errors(struct Options options)
pubmsg.qos = 1;
pubmsg.retained = 0;
property.identifier = USER_PROPERTY;
property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
property.value.data.data = "unsub user property";
property.value.data.len = strlen(property.value.data.data);
property.value.value.data = "unsub user property value";
@ -1197,7 +1197,7 @@ int test_qos_1_2_errors(struct Options options)
MQTTProperties_add(&pubmsg.properties, &property);
response = MQTTClient_publishMessage5(c, test_topic, &pubmsg, &dt);
assert("Good rc from publish", response.reasonCode == MQTTCLIENT_SUCCESS, "rc was %d", response.reasonCode);
assert("Good rc from publish", response.reasonCode == MQTTREASONCODE_SUCCESS, "rc was %d", response.reasonCode);
count = 0;
while (test_qos_1_2_errors_globals.published == 0 && ++count < 10)
@ -1211,7 +1211,7 @@ int test_qos_1_2_errors(struct Options options)
assert("Published called", test_qos_1_2_errors_globals.published == 1,
"published was %d", test_qos_1_2_errors_globals.published);
assert("Reason code was packet identifier not found",
test_qos_1_2_errors_globals.rc == NOT_AUTHORIZED,
test_qos_1_2_errors_globals.rc == MQTTREASONCODE_NOT_AUTHORIZED,
"Reason code was %d", test_qos_1_2_errors_globals.rc);
assert("Packet type was PUBACK", test_qos_1_2_errors_globals.packet_type == PUBACK,
"packet type was %d", test_qos_1_2_errors_globals.packet_type);
@ -1233,14 +1233,14 @@ int test_qos_1_2_errors(struct Options options)
assert("Published called", test_qos_1_2_errors_globals.published == 1,
"published was %d", test_qos_1_2_errors_globals.published);
assert("Reason code was packet identifier not found",
test_qos_1_2_errors_globals.rc == NOT_AUTHORIZED,
test_qos_1_2_errors_globals.rc == MQTTREASONCODE_NOT_AUTHORIZED,
"Reason code was %d", test_qos_1_2_errors_globals.rc);
assert("Packet type was PUBREC", test_qos_1_2_errors_globals.packet_type == PUBREC,
"packet type was %d", test_qos_1_2_errors_globals.packet_type);
test_qos_1_2_errors_globals.published = 0;
response = MQTTClient_publishMessage5(c, "test_qos_1_2_errors_pubcomp", &pubmsg, &dt);
assert("Good rc from publish", response.reasonCode == MQTTCLIENT_SUCCESS, "rc was %d", response.reasonCode);
assert("Good rc from publish", response.reasonCode == MQTTREASONCODE_SUCCESS, "rc was %d", response.reasonCode);
count = 0;
while (test_qos_1_2_errors_globals.published == 0 && ++count < 10)
@ -1254,12 +1254,12 @@ int test_qos_1_2_errors(struct Options options)
assert("Published called", test_qos_1_2_errors_globals.published == 1,
"published was %d", test_qos_1_2_errors_globals.published);
assert("Reason code was packet identifier not found",
test_qos_1_2_errors_globals.rc == PACKET_IDENTIFIER_NOT_FOUND,
test_qos_1_2_errors_globals.rc == MQTTREASONCODE_PACKET_IDENTIFIER_NOT_FOUND,
"Reason code was %d", test_qos_1_2_errors_globals.rc);
assert("Packet type was PUBCOMP", test_qos_1_2_errors_globals.packet_type == PUBCOMP,
"packet type was %d", test_qos_1_2_errors_globals.packet_type);
rc = MQTTClient_disconnect5(c, 1000, SUCCESS, NULL);
rc = MQTTClient_disconnect5(c, 1000, MQTTREASONCODE_SUCCESS, NULL);
exit:
MQTTClient_setTraceCallback(NULL);
@ -1312,15 +1312,15 @@ int test_request_response_messageArrived(void* context, char* topicName, int top
strcmp(test_request_response_globals.request_topic, topicName) == 0,
"topic was %s\n", topicName);
if (MQTTProperties_hasProperty(&message->properties, RESPONSE_TOPIC))
prop = MQTTProperties_getProperty(&message->properties, RESPONSE_TOPIC);
if (MQTTProperties_hasProperty(&message->properties, MQTTPROPERTY_CODE_RESPONSE_TOPIC))
prop = MQTTProperties_getProperty(&message->properties, MQTTPROPERTY_CODE_RESPONSE_TOPIC);
assert("Topic should be response",
strncmp(test_request_response_globals.response_topic, prop->value.data.data, prop->value.data.len) == 0,
"topic was %.4s\n", prop->value.data.data);
if (MQTTProperties_hasProperty(&message->properties, CORRELATION_DATA))
prop = MQTTProperties_getProperty(&message->properties, CORRELATION_DATA);
if (MQTTProperties_hasProperty(&message->properties, MQTTPROPERTY_CODE_CORRELATION_DATA))
prop = MQTTProperties_getProperty(&message->properties, MQTTPROPERTY_CODE_CORRELATION_DATA);
assert("Correlation data should be",
strncmp(test_request_response_globals.correlation_id, prop->value.data.data, prop->value.data.len) == 0,
@ -1391,8 +1391,8 @@ int test_request_response(struct Options options)
if (response.properties)
{
if (MQTTProperties_hasProperty(response.properties, SUBSCRIPTION_IDENTIFIERS_AVAILABLE))
subsids = MQTTProperties_getNumericValue(response.properties, SUBSCRIPTION_IDENTIFIERS_AVAILABLE);
if (MQTTProperties_hasProperty(response.properties, MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIERS_AVAILABLE))
subsids = MQTTProperties_getNumericValue(response.properties, MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIERS_AVAILABLE);
MyLog(LOGA_INFO, "Connack properties:");
logProperties(response.properties);
@ -1400,10 +1400,10 @@ int test_request_response(struct Options options)
}
response = MQTTClient_subscribe5(c, test_request_response_globals.response_topic, 2, NULL, NULL);
assert("Good rc from subscribe", response.reasonCode == GRANTED_QOS_2, "rc was %d", response.reasonCode);
assert("Good rc from subscribe", response.reasonCode == MQTTREASONCODE_GRANTED_QOS_2, "rc was %d", response.reasonCode);
response = MQTTClient_subscribe5(c, test_request_response_globals.request_topic, 2, NULL, NULL);
assert("Good rc from subscribe", response.reasonCode == GRANTED_QOS_2, "rc was %d", response.reasonCode);
assert("Good rc from subscribe", response.reasonCode == MQTTREASONCODE_GRANTED_QOS_2, "rc was %d", response.reasonCode);
messages_arrived = 0;
pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
@ -1411,18 +1411,18 @@ int test_request_response(struct Options options)
pubmsg.retained = 0;
pubmsg.qos = 2;
property.identifier = RESPONSE_TOPIC;
property.identifier = MQTTPROPERTY_CODE_RESPONSE_TOPIC;
property.value.data.data = test_request_response_globals.response_topic;
property.value.data.len = strlen(property.value.data.data);
MQTTProperties_add(&pubmsg.properties, &property);
property.identifier = CORRELATION_DATA;
property.identifier = MQTTPROPERTY_CODE_CORRELATION_DATA;
property.value.data.data = test_request_response_globals.correlation_id;
property.value.data.len = strlen(property.value.data.data);
MQTTProperties_add(&pubmsg.properties, &property);
response = MQTTClient_publishMessage5(c, test_request_response_globals.request_topic, &pubmsg, &dt);
assert("Good rc from publish", response.reasonCode == MQTTCLIENT_SUCCESS, "rc was %d", response.reasonCode);
assert("Good rc from publish", response.reasonCode == MQTTREASONCODE_SUCCESS, "rc was %d", response.reasonCode);
/* should get the request */
while (test_request_response_globals.messages_arrived < 1 && ++count < 10)
@ -1437,13 +1437,13 @@ int test_request_response(struct Options options)
test_request_response_globals.messages_arrived);
MQTTProperties_free(&pubmsg.properties);
property.identifier = CORRELATION_DATA;
property.identifier = MQTTPROPERTY_CODE_CORRELATION_DATA;
property.value.data.data = "request no 1";
property.value.data.len = strlen(property.value.data.data);
MQTTProperties_add(&pubmsg.properties, &property);
response = MQTTClient_publishMessage5(c, test_request_response_globals.response_topic, &pubmsg, &dt);
assert("Good rc from publish", response.reasonCode == MQTTCLIENT_SUCCESS, "rc was %d", response.reasonCode);
assert("Good rc from publish", response.reasonCode == MQTTREASONCODE_SUCCESS, "rc was %d", response.reasonCode);
/* should get the response */
while (test_request_response_globals.messages_arrived < 1 && ++count < 10)
@ -1457,7 +1457,7 @@ int test_request_response(struct Options options)
assert("1 message should have arrived", test_request_response_globals.messages_arrived == 1, "was %d",
test_request_response_globals.messages_arrived);
rc = MQTTClient_disconnect5(c, 1000, SUCCESS, NULL);
rc = MQTTClient_disconnect5(c, 1000, MQTTREASONCODE_SUCCESS, NULL);
MQTTProperties_free(&pubmsg.properties);
MQTTProperties_free(&subs_props);
@ -1503,10 +1503,10 @@ int test_subscribe_options_messageArrived(void* context, char* topicName, int to
if (test_subscribe_options_globals.messages_arrived == 1)
{
subsidcount = MQTTProperties_propertyCount(&message->properties, SUBSCRIPTION_IDENTIFIER);
subsidcount = MQTTProperties_propertyCount(&message->properties, MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER);
assert("Subsidcount is i", subsidcount == 1, "subsidcount is not correct %d\n", subsidcount);
subsid = MQTTProperties_getNumericValueAt(&message->properties, SUBSCRIPTION_IDENTIFIER, 0);
subsid = MQTTProperties_getNumericValueAt(&message->properties, MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER, 0);
assert("Subsid is 2", subsid == 2, "subsid is not correct %d\n", subsid);
}
@ -1571,18 +1571,18 @@ int test_subscribe_options(struct Options options)
MQTTResponse_free(response);
}
property.identifier = SUBSCRIPTION_IDENTIFIER;
property.identifier = MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER;
property.value.integer4 = 1;
MQTTProperties_add(&subs_props, &property);
subopts.noLocal = 1;
response = MQTTClient_subscribe5(c, test_subscribe_options_globals.topic, 2, &subopts, &subs_props);
assert("Good rc from subscribe", response.reasonCode == GRANTED_QOS_2, "rc was %d", response.reasonCode);
assert("Good rc from subscribe", response.reasonCode == MQTTREASONCODE_GRANTED_QOS_2, "rc was %d", response.reasonCode);
subs_props.array[0].value.integer4 = 2;
subopts.noLocal = 0;
subopts.retainHandling = 1;
response = MQTTClient_subscribe5(c, "#", 2, &subopts, &subs_props);
assert("Good rc from subscribe", response.reasonCode == GRANTED_QOS_2, "rc was %d", response.reasonCode);
assert("Good rc from subscribe", response.reasonCode == MQTTREASONCODE_GRANTED_QOS_2, "rc was %d", response.reasonCode);
messages_arrived = 0;
pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
@ -1591,7 +1591,7 @@ int test_subscribe_options(struct Options options)
pubmsg.qos = 2;
response = MQTTClient_publishMessage5(c, test_subscribe_options_globals.topic, &pubmsg, &dt);
assert("Good rc from publish", response.reasonCode == MQTTCLIENT_SUCCESS, "rc was %d", response.reasonCode);
assert("Good rc from publish", response.reasonCode == MQTTREASONCODE_SUCCESS, "rc was %d", response.reasonCode);
/* should get the request */
while (test_subscribe_options_globals.messages_arrived < 1 && ++count < 10)
@ -1605,7 +1605,7 @@ int test_subscribe_options(struct Options options)
assert("1 message should have arrived", test_subscribe_options_globals.messages_arrived == 1, "was %d",
test_subscribe_options_globals.messages_arrived);
rc = MQTTClient_disconnect5(c, 1000, SUCCESS, NULL);
rc = MQTTClient_disconnect5(c, 1000, MQTTREASONCODE_SUCCESS, NULL);
MQTTProperties_free(&pubmsg.properties);
MQTTProperties_free(&subs_props);
@ -1742,10 +1742,10 @@ int test_shared_subscriptions(struct Options options)
}
response = MQTTClient_subscribe5(c, test_shared_subscriptions_globals.shared_topic, 2, &subopts, &subs_props);
assert("Good rc from subscribe", response.reasonCode == GRANTED_QOS_2, "rc was %d", response.reasonCode);
assert("Good rc from subscribe", response.reasonCode == MQTTREASONCODE_GRANTED_QOS_2, "rc was %d", response.reasonCode);
response = MQTTClient_subscribe5(d, test_shared_subscriptions_globals.shared_topic, 2, &subopts, &subs_props);
assert("Good rc from subscribe", response.reasonCode == GRANTED_QOS_2, "rc was %d", response.reasonCode);
assert("Good rc from subscribe", response.reasonCode == MQTTREASONCODE_GRANTED_QOS_2, "rc was %d", response.reasonCode);
messages_arrived = 0;
pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
@ -1757,7 +1757,7 @@ int test_shared_subscriptions(struct Options options)
for (i = 0; i < 10; ++i)
{
response = MQTTClient_publishMessage5(c, test_shared_subscriptions_globals.topic, &pubmsg, &dt);
assert("Good rc from publish", response.reasonCode == MQTTCLIENT_SUCCESS, "rc was %d", response.reasonCode);
assert("Good rc from publish", response.reasonCode == MQTTREASONCODE_SUCCESS, "rc was %d", response.reasonCode);
/* should get the request */
while (test_shared_subscriptions_globals.messages_arrived < i+1 && ++count < 100)
@ -1772,7 +1772,7 @@ int test_shared_subscriptions(struct Options options)
test_shared_subscriptions_globals.messages_arrived);
}
rc = MQTTClient_disconnect5(c, 1000, SUCCESS, NULL);
rc = MQTTClient_disconnect5(c, 1000, MQTTREASONCODE_SUCCESS, NULL);
MQTTProperties_free(&pubmsg.properties);
MQTTProperties_free(&subs_props);

View File

@ -262,24 +262,24 @@ void logProperties(MQTTProperties *props)
switch (MQTTProperty_getType(id))
{
case PROPERTY_TYPE_BYTE:
case MQTTPROPERTY_TYPE_BYTE:
MyLog(LOGA_INFO, intformat, name, props->array[i].value.byte);
break;
case TWO_BYTE_INTEGER:
case MQTTPROPERTY_TYPE_TWO_BYTE_INTEGER:
MyLog(LOGA_INFO, intformat, name, props->array[i].value.integer2);
break;
case FOUR_BYTE_INTEGER:
case MQTTPROPERTY_TYPE_FOUR_BYTE_INTEGER:
MyLog(LOGA_INFO, intformat, name, props->array[i].value.integer4);
break;
case VARIABLE_BYTE_INTEGER:
case MQTTPROPERTY_TYPE_VARIABLE_BYTE_INTEGER:
MyLog(LOGA_INFO, intformat, name, props->array[i].value.integer4);
break;
case BINARY_DATA:
case UTF_8_ENCODED_STRING:
case MQTTPROPERTY_TYPE_BINARY_DATA:
case MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING:
MyLog(LOGA_INFO, "Property name %s value len %.*s", name,
props->array[i].value.data.len, props->array[i].value.data.data);
break;
case UTF_8_STRING_PAIR:
case MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR:
MyLog(LOGA_INFO, "Property name %s key %.*s value %.*s", name,
props->array[i].value.data.len, props->array[i].value.data.data,
props->array[i].value.value.len, props->array[i].value.value.data);
@ -321,8 +321,8 @@ int test_client_topic_aliases_messageArrived(void* context, char* topicName, int
{
const int props_count = 0;
assert("No topic alias", MQTTProperties_hasProperty(&message->properties, TOPIC_ALIAS) == 0,
"topic alias is %d\n", MQTTProperties_hasProperty(&message->properties, TOPIC_ALIAS));
assert("No topic alias", MQTTProperties_hasProperty(&message->properties, MQTTPROPERTY_CODE_TOPIC_ALIAS) == 0,
"topic alias is %d\n", MQTTProperties_hasProperty(&message->properties, MQTTPROPERTY_CODE_TOPIC_ALIAS));
assert("Topic should be name", strcmp(topicName, test_client_topic_aliases_globals.test_topic) == 0,
"Topic name was %s\n", topicName);
@ -357,7 +357,7 @@ void test_client_topic_aliases_onSubscribe(void* context, MQTTAsync_successData5
pubmsg.qos = 1;
/* first set the topic alias */
property.identifier = TOPIC_ALIAS;
property.identifier = MQTTPROPERTY_CODE_TOPIC_ALIAS;
property.value.integer2 = 1;
MQTTProperties_add(&pubmsg.properties, &property);
@ -397,7 +397,7 @@ void test_client_topic_aliases_onConnect(void* context, MQTTAsync_successData5*
MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
assert("Reason code should be 0", response->reasonCode == SUCCESS,
assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
"Reason code was %d\n", response->reasonCode);
MyLog(LOGA_INFO, "Connack properties:");
@ -412,7 +412,7 @@ void test_client_topic_aliases_onConnect(void* context, MQTTAsync_successData5*
pubmsg.retained = 0;
/* a Topic Alias of 0 is not allowed, so we should be disconnected */
property.identifier = TOPIC_ALIAS;
property.identifier = MQTTPROPERTY_CODE_TOPIC_ALIAS;
property.value.integer2 = 0;
MQTTProperties_add(&pubmsg.properties, &property);
@ -486,11 +486,11 @@ int test_client_topic_aliases(struct Options options)
opts.onFailure5 = NULL;
opts.context = c;
property.identifier = SESSION_EXPIRY_INTERVAL;
property.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL;
property.value.integer4 = 30;
MQTTProperties_add(&props, &property);
property.identifier = USER_PROPERTY;
property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
property.value.data.data = "test user property";
property.value.data.len = strlen(property.value.data.data);
property.value.value.data = "test user property value";
@ -565,8 +565,8 @@ int test_server_topic_aliases_messageArrived(void* context, char* topicName, int
{
const int props_count = 0;
if (MQTTProperties_hasProperty(&message->properties, TOPIC_ALIAS))
topicAlias = MQTTProperties_getNumericValue(&message->properties, TOPIC_ALIAS);
if (MQTTProperties_hasProperty(&message->properties, MQTTPROPERTY_CODE_TOPIC_ALIAS))
topicAlias = MQTTProperties_getNumericValue(&message->properties, MQTTPROPERTY_CODE_TOPIC_ALIAS);
if (received == 1)
{
@ -635,7 +635,7 @@ void test_server_topic_aliases_onConnect(void* context, MQTTAsync_successData5*
MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
assert("Reason code should be 0", response->reasonCode == SUCCESS,
assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
"Reason code was %d\n", response->reasonCode);
MyLog(LOGA_INFO, "Connack properties:");
@ -683,7 +683,7 @@ int test_server_topic_aliases(struct Options options)
assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
/* Allow at least one server topic alias */
property.identifier = TOPIC_ALIAS_MAXIMUM;
property.identifier = MQTTPROPERTY_CODE_TOPIC_ALIAS_MAXIMUM;
property.value.integer2 = 1;
MQTTProperties_add(&connect_props, &property);
@ -750,11 +750,11 @@ int test_subscription_ids_messageArrived(void* context, char* topicName, int top
{
int subsidcount = 0, i = 0;
subsidcount = MQTTProperties_propertyCount(&message->properties, SUBSCRIPTION_IDENTIFIER);
subsidcount = MQTTProperties_propertyCount(&message->properties, MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER);
for (i = 0; i < subsidcount; ++i)
{
int subsid = MQTTProperties_getNumericValueAt(&message->properties, SUBSCRIPTION_IDENTIFIER, i);
int subsid = MQTTProperties_getNumericValueAt(&message->properties, MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER, i);
assert("Subsid is i+1", subsid == i+1, "subsid is not correct %d\n", subsid);
}
logProperties(&message->properties);
@ -784,7 +784,7 @@ void test_subscription_ids_onSubscribe(void* context, MQTTAsync_successData5* re
if (++subs_count == 1)
{
/* subscribe to a wildcard */
property.identifier = SUBSCRIPTION_IDENTIFIER;
property.identifier = MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER;
property.value.integer4 = 2;
MQTTProperties_add(&opts.properties, &property);
@ -822,7 +822,7 @@ void test_subscription_ids_onConnect(void* context, MQTTAsync_successData5* resp
MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
assert("Reason code should be 0", response->reasonCode == SUCCESS,
assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
"Reason code was %d\n", response->reasonCode);
MyLog(LOGA_INFO, "Connack properties:");
@ -831,7 +831,7 @@ void test_subscription_ids_onConnect(void* context, MQTTAsync_successData5* resp
opts.onSuccess5 = test_subscription_ids_onSubscribe;
opts.context = c;
/* subscribe to the test topic */
property.identifier = SUBSCRIPTION_IDENTIFIER;
property.identifier = MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER;
property.value.integer4 = 1;
MQTTProperties_add(&opts.properties, &property);
@ -971,14 +971,14 @@ void test_flow_control_onConnect(void* context, MQTTAsync_successData5* response
MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
assert("Reason code should be 0", response->reasonCode == SUCCESS,
assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
"Reason code was %d\n", response->reasonCode);
MyLog(LOGA_INFO, "Connack properties:");
logProperties(&response->properties);
if (MQTTProperties_hasProperty(&response->properties, RECEIVE_MAXIMUM))
test_flow_control_globals.receive_maximum = MQTTProperties_getNumericValue(&response->properties, RECEIVE_MAXIMUM);
if (MQTTProperties_hasProperty(&response->properties, MQTTPROPERTY_CODE_RECEIVE_MAXIMUM))
test_flow_control_globals.receive_maximum = MQTTProperties_getNumericValue(&response->properties, MQTTPROPERTY_CODE_RECEIVE_MAXIMUM);
opts.onSuccess5 = test_flow_control_onSubscribe;
opts.context = c;
@ -1122,7 +1122,7 @@ void test_error_reporting_onSubscribe(void* context, MQTTAsync_successData5* res
opts.onSuccess5 = test_error_reporting_onUnsubscribe;
opts.context = c;
property.identifier = USER_PROPERTY;
property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
property.value.data.data = "test user property";
property.value.data.len = strlen(property.value.data.data);
property.value.value.data = "test user property value";
@ -1149,7 +1149,7 @@ void test_error_reporting_onConnect(void* context, MQTTAsync_successData5* respo
MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
assert("Reason code should be 0", response->reasonCode == SUCCESS,
assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
"Reason code was %d\n", response->reasonCode);
MyLog(LOGA_INFO, "Connack properties:");
@ -1158,15 +1158,15 @@ void test_error_reporting_onConnect(void* context, MQTTAsync_successData5* respo
opts.onSuccess5 = test_error_reporting_onSubscribe;
opts.context = c;
property.identifier = USER_PROPERTY;
property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
property.value.data.data = "test user property";
property.value.data.len = strlen(property.value.data.data);
property.value.value.data = "test user property value";
property.value.value.len = strlen(property.value.value.data);
MQTTProperties_add(&opts.properties, &property);
opts.subscribe_options_count = 2;
opts.subscribe_options_list = subopts;
opts.subscribeOptionsCount = 2;
opts.subscribeOptionsList = subopts;
rc = MQTTAsync_subscribeMany(c, 2, topics, qoss, &opts);
assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
@ -1287,7 +1287,7 @@ void test_qos_1_2_errors_onPublishFailure2(void* context, MQTTAsync_failureData5
pubmsg.qos = 2;
pubmsg.retained = 0;
property.identifier = USER_PROPERTY;
property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
property.value.data.data = "pub user property";
property.value.data.len = strlen(property.value.data.data);
property.value.value.data = "pub user property value";
@ -1296,7 +1296,7 @@ void test_qos_1_2_errors_onPublishFailure2(void* context, MQTTAsync_failureData5
rc = MQTTAsync_sendMessage(c, "test_qos_1_2_errors_pubcomp", &pubmsg, &opts);
assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
if (rc != SUCCESS)
if (rc != MQTTREASONCODE_SUCCESS)
test_qos_1_2_errors_globals.test_finished = 1;
MQTTProperties_free(&pubmsg.properties);
@ -1325,7 +1325,7 @@ void test_qos_1_2_errors_onPublishFailure(void* context, MQTTAsync_failureData5*
pubmsg.qos = 2;
pubmsg.retained = 0;
property.identifier = USER_PROPERTY;
property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
property.value.data.data = "pub user property";
property.value.data.len = strlen(property.value.data.data);
property.value.value.data = "pub user property value";
@ -1334,7 +1334,7 @@ void test_qos_1_2_errors_onPublishFailure(void* context, MQTTAsync_failureData5*
rc = MQTTAsync_sendMessage(c, test_qos_1_2_errors_globals.test_topic, &pubmsg, &opts);
assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
if (rc != SUCCESS)
if (rc != MQTTREASONCODE_SUCCESS)
test_qos_1_2_errors_globals.test_finished = 1;
MQTTProperties_free(&pubmsg.properties);
@ -1351,7 +1351,7 @@ void test_qos_1_2_errors_onConnect(void* context, MQTTAsync_successData5* respon
MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
assert("Reason code should be 0", response->reasonCode == SUCCESS,
assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
"Reason code was %d\n", response->reasonCode);
MyLog(LOGA_INFO, "Connack properties:");
@ -1366,7 +1366,7 @@ void test_qos_1_2_errors_onConnect(void* context, MQTTAsync_successData5* respon
pubmsg.qos = 1;
pubmsg.retained = 0;
property.identifier = USER_PROPERTY;
property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
property.value.data.data = "pub user property";
property.value.data.len = strlen(property.value.data.data);
property.value.value.data = "pub user property value";
@ -1375,7 +1375,7 @@ void test_qos_1_2_errors_onConnect(void* context, MQTTAsync_successData5* respon
rc = MQTTAsync_sendMessage(c, test_qos_1_2_errors_globals.test_topic, &pubmsg, &opts);
assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
if (rc != SUCCESS)
if (rc != MQTTREASONCODE_SUCCESS)
test_qos_1_2_errors_globals.test_finished = 1;
MQTTProperties_free(&pubmsg.properties);
@ -1476,16 +1476,16 @@ int test_request_response_messageArrived(void* context, char* topicName, int top
strcmp(test_request_response_globals.request_topic, topicName) == 0,
"topic was %s\n", topicName);
if (MQTTProperties_hasProperty(&message->properties, RESPONSE_TOPIC))
response_topic_prop = MQTTProperties_getProperty(&message->properties, RESPONSE_TOPIC);
if (MQTTProperties_hasProperty(&message->properties, MQTTPROPERTY_CODE_RESPONSE_TOPIC))
response_topic_prop = MQTTProperties_getProperty(&message->properties, MQTTPROPERTY_CODE_RESPONSE_TOPIC);
assert("Topic should be response",
strncmp(test_request_response_globals.response_topic, response_topic_prop->value.data.data,
response_topic_prop->value.data.len) == 0,
"topic was %.4s\n", response_topic_prop->value.data.data);
if (MQTTProperties_hasProperty(&message->properties, CORRELATION_DATA))
corr_prop = MQTTProperties_getProperty(&message->properties, CORRELATION_DATA);
if (MQTTProperties_hasProperty(&message->properties, MQTTPROPERTY_CODE_CORRELATION_DATA))
corr_prop = MQTTProperties_getProperty(&message->properties, MQTTPROPERTY_CODE_CORRELATION_DATA);
assert("Correlation data should be",
strncmp(test_request_response_globals.correlation_id, corr_prop->value.data.data,
@ -1498,7 +1498,7 @@ int test_request_response_messageArrived(void* context, char* topicName, int top
pubmsg.retained = 0;
pubmsg.qos = 1;
property.identifier = CORRELATION_DATA;
property.identifier = MQTTPROPERTY_CODE_CORRELATION_DATA;
property.value.data.data = test_request_response_globals.correlation_id;
property.value.data.len = strlen(property.value.data.data);
MQTTProperties_add(&pubmsg.properties, &property);
@ -1506,7 +1506,7 @@ int test_request_response_messageArrived(void* context, char* topicName, int top
memcpy(myTopicName, response_topic_prop->value.data.data, response_topic_prop->value.data.len);
myTopicName[response_topic_prop->value.data.len] = '\0';
rc = MQTTAsync_sendMessage(c, myTopicName, &pubmsg, &opts);
if (rc != SUCCESS)
if (rc != MQTTREASONCODE_SUCCESS)
test_request_response_globals.test_finished = 1;
assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
@ -1521,8 +1521,8 @@ int test_request_response_messageArrived(void* context, char* topicName, int top
strcmp(test_request_response_globals.response_topic, topicName) == 0,
"topic was %s\n", topicName);
if (MQTTProperties_hasProperty(&message->properties, CORRELATION_DATA))
corr_prop = MQTTProperties_getProperty(&message->properties, CORRELATION_DATA);
if (MQTTProperties_hasProperty(&message->properties, MQTTPROPERTY_CODE_CORRELATION_DATA))
corr_prop = MQTTProperties_getProperty(&message->properties, MQTTPROPERTY_CODE_CORRELATION_DATA);
assert("Correlation data should be",
strncmp(test_request_response_globals.correlation_id, corr_prop->value.data.data,
@ -1562,7 +1562,7 @@ void test_request_response_onSubscribe(void* context, MQTTAsync_successData5* re
for (i = 0; i < response->alt.sub.reasonCodeCount; ++i)
{
MyLog(LOGA_INFO, "Subscribe reason code %d", response->alt.sub.reasonCodes[i]);
assert("Reason code should be 2", response->alt.sub.reasonCodes[i] == GRANTED_QOS_2,
assert("Reason code should be 2", response->alt.sub.reasonCodes[i] == MQTTREASONCODE_GRANTED_QOS_2,
"Reason code was %d\n", response->alt.sub.reasonCodes[i]);
}
}
@ -1572,18 +1572,18 @@ void test_request_response_onSubscribe(void* context, MQTTAsync_successData5* re
pubmsg.retained = 0;
pubmsg.qos = 1;
property.identifier = RESPONSE_TOPIC;
property.identifier = MQTTPROPERTY_CODE_RESPONSE_TOPIC;
property.value.data.data = test_request_response_globals.response_topic;
property.value.data.len = strlen(property.value.data.data);
MQTTProperties_add(&pubmsg.properties, &property);
property.identifier = CORRELATION_DATA;
property.identifier = MQTTPROPERTY_CODE_CORRELATION_DATA;
property.value.data.data = test_request_response_globals.correlation_id;
property.value.data.len = strlen(property.value.data.data);
MQTTProperties_add(&pubmsg.properties, &property);
rc = MQTTAsync_sendMessage(c, test_request_response_globals.request_topic, &pubmsg, &opts);
if (rc != SUCCESS)
if (rc != MQTTREASONCODE_SUCCESS)
test_request_response_globals.test_finished = 1;
assert("Good rc from sendMessage", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
@ -1602,7 +1602,7 @@ void test_request_response_onConnect(void* context, MQTTAsync_successData5* resp
MyLog(LOGA_DEBUG, "In request response connect onSuccess callback, context %p", context);
assert("Reason code should be 0", response->reasonCode == SUCCESS,
assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
"Reason code was %d\n", response->reasonCode);
MyLog(LOGA_INFO, "Connack properties:");
@ -1611,7 +1611,7 @@ void test_request_response_onConnect(void* context, MQTTAsync_successData5* resp
opts.onSuccess5 = test_request_response_onSubscribe;
opts.context = c;
rc = MQTTAsync_subscribeMany(c, 2, topics, qos, &opts);
if (rc != SUCCESS)
if (rc != MQTTREASONCODE_SUCCESS)
test_request_response_globals.test_finished = 1;
assert("Good rc from subscribeMany", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
}
@ -1673,7 +1673,7 @@ struct
char* topic1;
char* topic2;
int messages_arrived;
} test_subscribe_options_globals =
} test_subscribeOptions_globals =
{
0,
"subscribe options topic",
@ -1682,12 +1682,12 @@ struct
};
int test_subscribe_options_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
int test_subscribeOptions_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message)
{
MQTTAsync c = (MQTTAsync)context;
int rc;
test_subscribe_options_globals.messages_arrived++;
test_subscribeOptions_globals.messages_arrived++;
assert("Message structure version should be 1", message->struct_version == 1,
"message->struct_version was %d", message->struct_version);
@ -1697,17 +1697,17 @@ int test_subscribe_options_messageArrived(void* context, char* topicName, int to
if (message->struct_version == 1)
logProperties(&message->properties);
if (test_subscribe_options_globals.messages_arrived == 1)
if (test_subscribeOptions_globals.messages_arrived == 1)
{
int subsidcount, subsid;
subsidcount = MQTTProperties_propertyCount(&message->properties, SUBSCRIPTION_IDENTIFIER);
subsidcount = MQTTProperties_propertyCount(&message->properties, MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER);
assert("Subsidcount is i", subsidcount == 1, "subsidcount is not correct %d\n", subsidcount);
subsid = MQTTProperties_getNumericValueAt(&message->properties, SUBSCRIPTION_IDENTIFIER, 0);
subsid = MQTTProperties_getNumericValueAt(&message->properties, MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER, 0);
assert("Subsid is 2", subsid == 2, "subsid is not correct %d\n", subsid);
test_subscribe_options_globals.test_finished = 1;
test_subscribeOptions_globals.test_finished = 1;
}
MQTTAsync_freeMessage(&message);
@ -1717,7 +1717,7 @@ int test_subscribe_options_messageArrived(void* context, char* topicName, int to
}
void test_subscribe_options_onSubscribe(void* context, MQTTAsync_successData5* response)
void test_subscribeOptions_onSubscribe(void* context, MQTTAsync_successData5* response)
{
MQTTAsync c = (MQTTAsync)context;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
@ -1727,7 +1727,7 @@ void test_subscribe_options_onSubscribe(void* context, MQTTAsync_successData5* r
MyLog(LOGA_DEBUG, "In subscribe options connect onSuccess callback, context %p", context);
called++;
assert("Reason code should be 0", response->reasonCode == GRANTED_QOS_2,
assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_GRANTED_QOS_2,
"Reason code was %d\n", response->reasonCode);
if (response->properties.count > 0)
@ -1740,17 +1740,17 @@ void test_subscribe_options_onSubscribe(void* context, MQTTAsync_successData5* r
{
MQTTProperty property;
property.identifier = SUBSCRIPTION_IDENTIFIER;
property.identifier = MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER;
property.value.integer4 = 2;
MQTTProperties_add(&opts.properties, &property);
opts.onSuccess5 = test_subscribe_options_onSubscribe;
opts.onSuccess5 = test_subscribeOptions_onSubscribe;
opts.context = c;
opts.subscribe_options.retainHandling = 2;
opts.subscribe_options.retainAsPublished = 1;
rc = MQTTAsync_subscribe(c, test_subscribe_options_globals.topic2, 2, &opts);
if (rc != SUCCESS)
test_subscribe_options_globals.test_finished = 1;
opts.subscribeOptions.retainHandling = 2;
opts.subscribeOptions.retainAsPublished = 1;
rc = MQTTAsync_subscribe(c, test_subscribeOptions_globals.topic2, 2, &opts);
if (rc != MQTTREASONCODE_SUCCESS)
test_subscribeOptions_globals.test_finished = 1;
assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
MQTTProperties_free(&opts.properties);
@ -1764,15 +1764,15 @@ void test_subscribe_options_onSubscribe(void* context, MQTTAsync_successData5* r
pubmsg.retained = 0;
pubmsg.qos = 2;
rc = MQTTAsync_sendMessage(c, test_subscribe_options_globals.topic1, &pubmsg, &opts);
rc = MQTTAsync_sendMessage(c, test_subscribeOptions_globals.topic1, &pubmsg, &opts);
assert("Good rc from send", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
if (rc != MQTTASYNC_SUCCESS)
test_subscribe_options_globals.test_finished = 1;
test_subscribeOptions_globals.test_finished = 1;
}
}
void test_subscribe_options_onConnect(void* context, MQTTAsync_successData5* response)
void test_subscribeOptions_onConnect(void* context, MQTTAsync_successData5* response)
{
MQTTAsync c = (MQTTAsync)context;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
@ -1781,21 +1781,21 @@ void test_subscribe_options_onConnect(void* context, MQTTAsync_successData5* res
MyLog(LOGA_DEBUG, "In subscribe options connect onSuccess callback, context %p", context);
assert("Reason code should be 0", response->reasonCode == SUCCESS,
assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
"Reason code was %d\n", response->reasonCode);
MyLog(LOGA_INFO, "Connack properties:");
logProperties(&response->properties);
property.identifier = SUBSCRIPTION_IDENTIFIER;
property.identifier = MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER;
property.value.integer4 = 1;
MQTTProperties_add(&opts.properties, &property);
opts.subscribe_options.noLocal = 1;
opts.subscribeOptions.noLocal = 1;
opts.onSuccess5 = test_subscribe_options_onSubscribe;
opts.onSuccess5 = test_subscribeOptions_onSubscribe;
opts.context = c;
rc = MQTTAsync_subscribe(c, test_subscribe_options_globals.topic1, 2, &opts);
if (rc != SUCCESS)
rc = MQTTAsync_subscribe(c, test_subscribeOptions_globals.topic1, 2, &opts);
if (rc != MQTTREASONCODE_SUCCESS)
test_request_response_globals.test_finished = 1;
assert("Good rc from subscribeMany", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
@ -1803,7 +1803,7 @@ void test_subscribe_options_onConnect(void* context, MQTTAsync_successData5* res
}
int test_subscribe_options(struct Options options)
int test_subscribeOptions(struct Options options)
{
MQTTAsync c;
MQTTAsync_connectOptions opts = MQTTAsync_connectOptions_initializer5;
@ -1822,11 +1822,11 @@ int test_subscribe_options(struct Options options)
goto exit;
}
rc = MQTTAsync_setCallbacks(c, c, NULL, test_subscribe_options_messageArrived, NULL);
rc = MQTTAsync_setCallbacks(c, c, NULL, test_subscribeOptions_messageArrived, NULL);
assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
opts.MQTTVersion = options.MQTTVersion;
opts.onSuccess5 = test_subscribe_options_onConnect;
opts.onSuccess5 = test_subscribeOptions_onConnect;
opts.context = c;
opts.cleanstart = 1;
@ -1836,7 +1836,7 @@ int test_subscribe_options(struct Options options)
if (rc != MQTTASYNC_SUCCESS)
goto exit;
while (test_subscribe_options_globals.test_finished == 0)
while (test_subscribeOptions_globals.test_finished == 0)
#if defined(WIN32)
Sleep(100);
#else
@ -1905,7 +1905,7 @@ void test_shared_subscriptions_onSubscribe(void* context, MQTTAsync_successData5
called++;
MyLog(LOGA_DEBUG, "In subscribe options connect onSuccess callback, context %p, called %d", context, called);
assert("Reason code should be 0", response->reasonCode == GRANTED_QOS_2,
assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_GRANTED_QOS_2,
"Reason code was %d\n", response->reasonCode);
if (response->properties.count > 0)
@ -1933,7 +1933,7 @@ void test_shared_subscriptions_onSubscribe(void* context, MQTTAsync_successData5
assert("Good rc from send", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
if (rc != MQTTASYNC_SUCCESS)
{
test_subscribe_options_globals.test_finished = 1;
test_subscribeOptions_globals.test_finished = 1;
break;
}
}
@ -1950,14 +1950,14 @@ void test_shared_subscriptions_onConnectd(void* context, MQTTAsync_successData5*
MyLog(LOGA_DEBUG, "In shared subscriptions connect d onSuccess callback, context %p", context);
assert("Reason code should be 0", response->reasonCode == SUCCESS,
assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
"Reason code was %d\n", response->reasonCode);
opts.onSuccess5 = test_shared_subscriptions_onSubscribe;
opts.context = d;
rc = MQTTAsync_subscribe(d, test_shared_subscriptions_globals.shared_topic, 2, &opts);
assert("Good rc from subscribe", rc == SUCCESS, "rc was %d", rc);
if (rc != SUCCESS)
assert("Good rc from subscribe", rc == MQTTREASONCODE_SUCCESS, "rc was %d", rc);
if (rc != MQTTREASONCODE_SUCCESS)
test_shared_subscriptions_globals.test_finished = 1;
}
@ -1971,14 +1971,14 @@ void test_shared_subscriptions_onConnectc(void* context, MQTTAsync_successData5*
MyLog(LOGA_DEBUG, "In shared subscriptions connect c onSuccess callback, context %p", context);
assert("Reason code should be 0", response->reasonCode == SUCCESS,
assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
"Reason code was %d\n", response->reasonCode);
opts.onSuccess5 = test_shared_subscriptions_onSubscribe;
opts.context = c;
rc = MQTTAsync_subscribe(c, test_shared_subscriptions_globals.shared_topic, 2, &opts);
assert("Good rc from subscribe", rc == SUCCESS, "rc was %d", rc);
if (rc != SUCCESS)
assert("Good rc from subscribe", rc == MQTTREASONCODE_SUCCESS, "rc was %d", rc);
if (rc != MQTTREASONCODE_SUCCESS)
test_shared_subscriptions_globals.test_finished = 1;
}
@ -2081,7 +2081,7 @@ int main(int argc, char** argv)
test_error_reporting,
test_qos_1_2_errors,
test_request_response,
test_subscribe_options,
test_subscribeOptions,
test_shared_subscriptions
}; /* indexed starting from 1 */
MQTTAsync_nameValue* info;

View File

@ -302,7 +302,7 @@ void test1_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
pubmsg.qos = qos;
pubmsg.retained = 0;
property.identifier = USER_PROPERTY;
property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
property.value.data.data = "test user property";
property.value.data.len = strlen(property.value.data.data);
property.value.value.data = "test user property value";
@ -368,24 +368,24 @@ void logProperties(MQTTProperties *props)
switch (MQTTProperty_getType(id))
{
case PROPERTY_TYPE_BYTE:
case MQTTPROPERTY_TYPE_BYTE:
MyLog(LOGA_INFO, intformat, name, props->array[i].value.byte);
break;
case TWO_BYTE_INTEGER:
case MQTTPROPERTY_TYPE_TWO_BYTE_INTEGER:
MyLog(LOGA_INFO, intformat, name, props->array[i].value.integer2);
break;
case FOUR_BYTE_INTEGER:
case MQTTPROPERTY_TYPE_FOUR_BYTE_INTEGER:
MyLog(LOGA_INFO, intformat, name, props->array[i].value.integer4);
break;
case VARIABLE_BYTE_INTEGER:
case MQTTPROPERTY_TYPE_VARIABLE_BYTE_INTEGER:
MyLog(LOGA_INFO, intformat, name, props->array[i].value.integer4);
break;
case BINARY_DATA:
case UTF_8_ENCODED_STRING:
case MQTTPROPERTY_TYPE_BINARY_DATA:
case MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING:
MyLog(LOGA_INFO, "Property name %s value %.*s", name,
props->array[i].value.data.len, props->array[i].value.data.data);
break;
case UTF_8_STRING_PAIR:
case MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR:
MyLog(LOGA_INFO, "Property name %s key %.*s value %.*s", name,
props->array[i].value.data.len, props->array[i].value.data.data,
props->array[i].value.value.len, props->array[i].value.value.data);
@ -441,11 +441,11 @@ int test1(struct Options options)
opts.will->topicName = "will topic";
opts.will = NULL;
property.identifier = SESSION_EXPIRY_INTERVAL;
property.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL;
property.value.integer4 = 30;
MQTTProperties_add(&props, &property);
property.identifier = USER_PROPERTY;
property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
property.value.data.data = "test user property";
property.value.data.len = strlen(property.value.data.data);
property.value.value.data = "test user property value";
@ -467,7 +467,7 @@ int test1(struct Options options)
}
subopts.retainAsPublished = 1;
property.identifier = SUBSCRIPTION_IDENTIFIER;
property.identifier = MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER;
property.value.integer4 = 33;
MQTTProperties_add(&props, &property);
response = MQTTClient_subscribe5(c, test_topic, subsqos, &subopts, &props);
@ -487,7 +487,7 @@ int test1(struct Options options)
MyLog(LOGA_DEBUG, "Stopping\n");
MQTTProperties_free(&props);
property.identifier = USER_PROPERTY;
property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
property.value.data.data = "User property name";
property.value.data.len = strlen(property.value.data.data);
property.value.value.data = "User property value";
@ -499,18 +499,18 @@ int test1(struct Options options)
MQTTResponse_free(response);
MQTTProperties_free(&props);
property.identifier = SESSION_EXPIRY_INTERVAL;
property.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL;
property.value.integer4 = 0;
MQTTProperties_add(&props, &property);
rc = MQTTClient_disconnect5(c, 0, SUCCESS, &props);
rc = MQTTClient_disconnect5(c, 0, MQTTREASONCODE_SUCCESS, &props);
assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
/* Just to make sure we can connect again */
response = MQTTClient_connect5(c, &opts, NULL, NULL);
assert("Connect successful", response.reasonCode == MQTTCLIENT_SUCCESS, "rc was %d", response.reasonCode);
MQTTResponse_free(response);
rc = MQTTClient_disconnect5(c, 0, SUCCESS, &props);
rc = MQTTClient_disconnect5(c, 0, MQTTREASONCODE_SUCCESS, &props);
assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
MQTTProperties_free(&props);
@ -689,7 +689,7 @@ int test2(struct Options options)
response = MQTTClient_unsubscribe5(c, test_topic, &props);
assert("Unsubscribe successful", response.reasonCode == MQTTCLIENT_SUCCESS, "rc was %d", rc);
rc = MQTTClient_disconnect5(c, 0, SUCCESS, &props);
rc = MQTTClient_disconnect5(c, 0, MQTTREASONCODE_SUCCESS, &props);
assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
MQTTClient_destroy(&c);
@ -825,7 +825,7 @@ int test4_run(int qos)
MyLog(LOGA_DEBUG, "Cleanup by connecting clean start, add session expiry > 0\n");
opts.cleanstart = 1;
property.identifier = SESSION_EXPIRY_INTERVAL;
property.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL;
property.value.integer4 = 30; /* in seconds */
MQTTProperties_add(&props, &property);
response = MQTTClient_connect5(c, &opts, &props, NULL);
@ -848,7 +848,7 @@ int test4_run(int qos)
}
/* disconnect immediately without receiving the incoming messages */
MQTTClient_disconnect5(c, 0, SUCCESS, NULL); /* now there should be "orphaned" publications */
MQTTClient_disconnect5(c, 0, MQTTREASONCODE_SUCCESS, NULL); /* now there should be "orphaned" publications */
rc = MQTTClient_getPendingDeliveryTokens(c, &tokens);
assert("getPendingDeliveryTokens rc == 0", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
@ -922,7 +922,7 @@ int test4_run(int qos)
assert("getPendingDeliveryTokens rc == 0", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
assert("should get no tokens back", tokens == NULL, "tokens was %p", tokens);
rc = MQTTClient_disconnect5(c, 0, SUCCESS, NULL);
rc = MQTTClient_disconnect5(c, 0, MQTTREASONCODE_SUCCESS, NULL);
MQTTClient_destroy(&c);
@ -987,7 +987,7 @@ int test5(struct Options options)
opts.serverURIs = options.haconnections;
opts.serverURIcount = options.hacount;
}
property.identifier = SESSION_EXPIRY_INTERVAL;
property.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL;
property.value.integer4 = 30;
MQTTProperties_add(&props, &property);
@ -1011,7 +1011,7 @@ int test5(struct Options options)
assert("Good rc from publish", response.reasonCode == MQTTCLIENT_SUCCESS, "rc was %d", response.reasonCode);
}
MQTTClient_disconnect5(c, 1000, SUCCESS, NULL); /* now there should be no "orphaned" publications */
MQTTClient_disconnect5(c, 1000, MQTTREASONCODE_SUCCESS, NULL); /* now there should be no "orphaned" publications */
MyLog(LOGA_DEBUG, "Disconnected");
rc = MQTTClient_getPendingDeliveryTokens(c, &tokens);
@ -1131,7 +1131,7 @@ int test6(struct Options options)
assert("Good rc from connect", response.reasonCode == MQTTCLIENT_SUCCESS, "rc was %d\n", response.reasonCode);
response = MQTTClient_subscribe5(test6_c2, test6_will_topic, 2, NULL, NULL);
assert("Good rc from subscribe", response.reasonCode == GRANTED_QOS_2, "rc was %d\n", response.reasonCode);
assert("Good rc from subscribe", response.reasonCode == MQTTREASONCODE_GRANTED_QOS_2, "rc was %d\n", response.reasonCode);
/* now send the command which will break the connection and cause the will message to be sent */
response = MQTTClient_publish5(test6_c1, mqttsas_topic, (int)strlen("TERMINATE"), "TERMINATE", 0, 0, NULL, NULL);
@ -1163,7 +1163,7 @@ int test6(struct Options options)
rc = MQTTClient_isConnected(test6_c1);
assert("Client-1 not connected", rc == 0, "isconnected is %d", rc);
rc = MQTTClient_disconnect5(test6_c2, 100L, SUCCESS, NULL);
rc = MQTTClient_disconnect5(test6_c2, 100L, MQTTREASONCODE_SUCCESS, NULL);
assert("Good rc from disconnect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
MQTTClient_destroy(&test6_c1);
@ -1243,7 +1243,7 @@ int test6a(struct Options options)
assert("Good rc from connect", response.reasonCode == MQTTCLIENT_SUCCESS, "rc was %d\n", response.reasonCode);
response = MQTTClient_subscribe5(test6_c2, test6_will_topic, 2, NULL, NULL);
assert("Good rc from subscribe", response.reasonCode == GRANTED_QOS_2, "rc was %d\n", response.reasonCode);
assert("Good rc from subscribe", response.reasonCode == MQTTREASONCODE_GRANTED_QOS_2, "rc was %d\n", response.reasonCode);
/* now send the command which will break the connection and cause the will message to be sent */
response = MQTTClient_publish5(test6_c1, mqttsas_topic, (int)strlen("TERMINATE"), "TERMINATE", 0, 0, NULL, NULL);
@ -1275,7 +1275,7 @@ int test6a(struct Options options)
rc = MQTTClient_isConnected(test6_c1);
assert("Client-1 not connected", rc == 0, "isconnected is %d", rc);
rc = MQTTClient_disconnect5(test6_c2, 100L, SUCCESS, NULL);
rc = MQTTClient_disconnect5(test6_c2, 100L, MQTTREASONCODE_SUCCESS, NULL);
assert("Good rc from disconnect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
MQTTClient_destroy(&test6_c1);

View File

@ -266,24 +266,24 @@ void logProperties(MQTTProperties *props)
switch (MQTTProperty_getType(id))
{
case PROPERTY_TYPE_BYTE:
case MQTTPROPERTY_TYPE_BYTE:
MyLog(LOGA_INFO, intformat, name, props->array[i].value.byte);
break;
case TWO_BYTE_INTEGER:
case MQTTPROPERTY_TYPE_TWO_BYTE_INTEGER:
MyLog(LOGA_INFO, intformat, name, props->array[i].value.integer2);
break;
case FOUR_BYTE_INTEGER:
case MQTTPROPERTY_TYPE_FOUR_BYTE_INTEGER:
MyLog(LOGA_INFO, intformat, name, props->array[i].value.integer4);
break;
case VARIABLE_BYTE_INTEGER:
case MQTTPROPERTY_TYPE_VARIABLE_BYTE_INTEGER:
MyLog(LOGA_INFO, intformat, name, props->array[i].value.integer4);
break;
case BINARY_DATA:
case UTF_8_ENCODED_STRING:
case MQTTPROPERTY_TYPE_BINARY_DATA:
case MQTTPROPERTY_TYPE_UTF_8_ENCODED_STRING:
MyLog(LOGA_INFO, "Property name %s value len %.*s", name,
props->array[i].value.data.len, props->array[i].value.data.data);
break;
case UTF_8_STRING_PAIR:
case MQTTPROPERTY_TYPE_UTF_8_STRING_PAIR:
MyLog(LOGA_INFO, "Property name %s key %.*s value %.*s", name,
props->array[i].value.data.len, props->array[i].value.data.data,
props->array[i].value.value.len, props->array[i].value.value.data);
@ -321,9 +321,9 @@ void test1_onUnsubscribe(void* context, MQTTAsync_successData5* response)
opts.onSuccess = test1_onDisconnect;
opts.context = c;
opts.reasonCode = UNSPECIFIED_ERROR;
opts.reasonCode = MQTTREASONCODE_UNSPECIFIED_ERROR;
property.identifier = SESSION_EXPIRY_INTERVAL;
property.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL;
property.value.integer4 = 0;
MQTTProperties_add(&opts.properties, &property);
@ -357,7 +357,7 @@ int test1_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync
MQTTProperty property;
MQTTProperties props = MQTTProperties_initializer;
property.identifier = USER_PROPERTY;
property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
property.value.data.data = "test user property";
property.value.data.len = strlen(property.value.data.data);
property.value.value.data = "test user property value";
@ -379,7 +379,7 @@ int test1_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync
MQTTProperties props = MQTTProperties_initializer;
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
property.identifier = USER_PROPERTY;
property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
property.value.data.data = "test user property";
property.value.data.len = strlen(property.value.data.data);
property.value.value.data = "test user property value";
@ -410,13 +410,13 @@ void test1_onSubscribe(void* context, MQTTAsync_successData5* response)
MQTTAsync_callOptions opts = MQTTAsync_callOptions_initializer;
MyLog(LOGA_DEBUG, "In subscribe onSuccess callback %p granted qos %d", c, response->reasonCode);
assert("Subscribe response should be 2", response->reasonCode == GRANTED_QOS_2,
assert("Subscribe response should be 2", response->reasonCode == MQTTREASONCODE_GRANTED_QOS_2,
"response was %d", response->reasonCode);
MyLog(LOGA_INFO, "Suback properties:");
logProperties(&response->properties);
property.identifier = USER_PROPERTY;
property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
property.value.data.data = "test user property";
property.value.data.len = strlen(property.value.data.data);
property.value.value.data = "test user property value";
@ -444,7 +444,7 @@ void test1_onConnect(void* context, MQTTAsync_successData5* response)
MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
assert("Reason code should be 0", response->reasonCode == SUCCESS,
assert("Reason code should be 0", response->reasonCode == MQTTREASONCODE_SUCCESS,
"Reason code was %d\n", response->reasonCode);
MyLog(LOGA_INFO, "Connack properties:");
@ -453,12 +453,12 @@ void test1_onConnect(void* context, MQTTAsync_successData5* response)
opts.onSuccess5 = test1_onSubscribe;
opts.context = c;
property.identifier = SUBSCRIPTION_IDENTIFIER;
property.identifier = MQTTPROPERTY_CODE_SUBSCRIPTION_IDENTIFIER;
property.value.integer4 = 33;
MQTTProperties_add(&props, &property);
opts.properties = props;
opts.subscribe_options.retainAsPublished = 1;
opts.subscribeOptions.retainAsPublished = 1;
rc = MQTTAsync_subscribe(c, test_topic, 2, &opts);
assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
@ -516,11 +516,11 @@ int test1(struct Options options)
opts.onFailure5 = NULL;
opts.context = c;
property.identifier = SESSION_EXPIRY_INTERVAL;
property.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL;
property.value.integer4 = 30;
MQTTProperties_add(&props, &property);
property.identifier = USER_PROPERTY;
property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
property.value.data.data = "test user property";
property.value.data.len = strlen(property.value.data.data);
property.value.value.data = "test user property value";
@ -928,7 +928,7 @@ int test4_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync
opts.onSuccess5 = test1_onUnsubscribe;
opts.context = c;
property.identifier = USER_PROPERTY;
property.identifier = MQTTPROPERTY_CODE_USER_PROPERTY;
property.value.data.data = "test user property";
property.value.data.len = strlen(property.value.data.data);
property.value.value.data = "test user property value";
@ -983,7 +983,7 @@ void test4_onConnect(void* context, MQTTAsync_successData5* response)
MQTTAsync_callOptions opts = MQTTAsync_callOptions_initializer;
int rc;
test4_packet_size = MQTTProperties_getNumericValue(&response->properties, MAXIMUM_PACKET_SIZE);
test4_packet_size = MQTTProperties_getNumericValue(&response->properties, MQTTPROPERTY_CODE_MAXIMUM_PACKET_SIZE);
MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
opts.onSuccess5 = test4_onSubscribe;
@ -1421,7 +1421,7 @@ int test7(struct Options options)
MyLog(LOGA_DEBUG, "Connecting");
opts.cleanstart = 1;
opts.connectProperties = &props;
property.identifier = SESSION_EXPIRY_INTERVAL;
property.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL;
property.value.integer4 = 999999;
MQTTProperties_add(opts.connectProperties, &property);
opts.onSuccess5 = test7_onConnect;
@ -1746,7 +1746,7 @@ int test8(struct Options options)
MyLog(LOGA_DEBUG, "Connecting");
opts.onSuccess5 = test8_onConnect;
property.identifier = SESSION_EXPIRY_INTERVAL;
property.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL;
property.value.integer4 = 30;
MQTTProperties_add(&props, &property);