Commit ced0d0ef authored by Ian Craggs's avatar Ian Craggs

Make all tests in test45.c work with MQTT 5

parent 167278c0
...@@ -1007,6 +1007,11 @@ static void MQTTAsync_checkDisconnect(MQTTAsync handle, MQTTAsync_command* comma ...@@ -1007,6 +1007,11 @@ static void MQTTAsync_checkDisconnect(MQTTAsync handle, MQTTAsync_command* comma
Log(TRACE_MIN, -1, "Calling disconnect complete for client %s", m->c->clientID); Log(TRACE_MIN, -1, "Calling disconnect complete for client %s", m->c->clientID);
(*(command->onSuccess))(command->context, NULL); (*(command->onSuccess))(command->context, NULL);
} }
else if (command->onSuccess5)
{
Log(TRACE_MIN, -1, "Calling disconnect complete for client %s", m->c->clientID);
(*(command->onSuccess5))(command->context, NULL);
}
} }
FUNC_EXIT; FUNC_EXIT;
} }
...@@ -1141,7 +1146,9 @@ static void MQTTAsync_writeComplete(int socket, int rc) ...@@ -1141,7 +1146,9 @@ static void MQTTAsync_writeComplete(int socket, int rc)
{ {
if (command->type == PUBLISH) if (command->type == PUBLISH)
{ {
if (rc == 1 && command->onSuccess) if (rc == 1)
{
if (command->onSuccess)
{ {
MQTTAsync_successData data; MQTTAsync_successData data;
...@@ -1154,7 +1161,24 @@ static void MQTTAsync_writeComplete(int socket, int rc) ...@@ -1154,7 +1161,24 @@ static void MQTTAsync_writeComplete(int socket, int rc)
Log(TRACE_MIN, -1, "Calling publish success for client %s", m->c->clientID); Log(TRACE_MIN, -1, "Calling publish success for client %s", m->c->clientID);
(*(command->onSuccess))(command->context, &data); (*(command->onSuccess))(command->context, &data);
} }
else if (rc == -1 && command->onFailure) else if (command->onSuccess5)
{
MQTTAsync_successData5 data = MQTTAsync_successData5_initializer;
data.token = command->token;
data.alt.pub.destinationName = command->details.pub.destinationName;
data.alt.pub.message.payload = command->details.pub.payload;
data.alt.pub.message.payloadlen = command->details.pub.payloadlen;
data.alt.pub.message.qos = command->details.pub.qos;
data.alt.pub.message.retained = command->details.pub.retained;
data.props = command->properties;
Log(TRACE_MIN, -1, "Calling publish success for client %s", m->c->clientID);
(*(command->onSuccess5))(command->context, &data);
}
}
else if (rc == -1)
{
if (command->onFailure)
{ {
MQTTAsync_failureData data; MQTTAsync_failureData data;
...@@ -1164,6 +1188,17 @@ static void MQTTAsync_writeComplete(int socket, int rc) ...@@ -1164,6 +1188,17 @@ static void MQTTAsync_writeComplete(int socket, int rc)
Log(TRACE_MIN, -1, "Calling publish failure for client %s", m->c->clientID); Log(TRACE_MIN, -1, "Calling publish failure for client %s", m->c->clientID);
(*(command->onFailure))(command->context, &data); (*(command->onFailure))(command->context, &data);
} }
else if (command->onFailure5)
{
MQTTAsync_failureData5 data;
data.token = command->token;
data.code = rc;
data.message = NULL;
Log(TRACE_MIN, -1, "Calling publish failure for client %s", m->c->clientID);
(*(command->onFailure5))(command->context, &data);
}
}
} }
if (com) if (com)
{ {
...@@ -1269,10 +1304,10 @@ static int MQTTAsync_processCommand(void) ...@@ -1269,10 +1304,10 @@ static int MQTTAsync_processCommand(void)
Log(TRACE_PROTOCOL, -1, "Connecting to serverURI %s with MQTT version %d", serverURI, command->command.details.conn.MQTTVersion); Log(TRACE_PROTOCOL, -1, "Connecting to serverURI %s with MQTT version %d", serverURI, command->command.details.conn.MQTTVersion);
#if defined(OPENSSL) #if defined(OPENSSL)
rc = MQTTProtocol_connect(serverURI, command->client->c, command->client->ssl, command->command.details.conn.MQTTVersion, rc = MQTTProtocol_connect(serverURI, command->client->c, command->client->ssl, command->command.details.conn.MQTTVersion,
NULL, NULL); command->client->connectProps, command->client->willProps);
#else #else
rc = MQTTProtocol_connect(serverURI, command->client->c, command->command.details.conn.MQTTVersion, rc = MQTTProtocol_connect(serverURI, command->client->c, command->command.details.conn.MQTTVersion,
NULL, NULL); command->client->connectProps, command->client->willProps);
#endif #endif
if (command->client->c->connect_state == 0) if (command->client->c->connect_state == 0)
rc = SOCKET_ERROR; rc = SOCKET_ERROR;
...@@ -1358,6 +1393,20 @@ static int MQTTAsync_processCommand(void) ...@@ -1358,6 +1393,20 @@ static int MQTTAsync_processCommand(void)
Log(TRACE_MIN, -1, "Calling publish success for client %s", command->client->c->clientID); Log(TRACE_MIN, -1, "Calling publish success for client %s", command->client->c->clientID);
(*(command->command.onSuccess))(command->command.context, &data); (*(command->command.onSuccess))(command->command.context, &data);
} }
else if (command->command.onSuccess5)
{
MQTTAsync_successData5 data = MQTTAsync_successData5_initializer;
data.token = command->command.token;
data.alt.pub.destinationName = command->command.details.pub.destinationName;
data.alt.pub.message.payload = command->command.details.pub.payload;
data.alt.pub.message.payloadlen = command->command.details.pub.payloadlen;
data.alt.pub.message.qos = command->command.details.pub.qos;
data.alt.pub.message.retained = command->command.details.pub.retained;
data.props = command->command.properties;
Log(TRACE_MIN, -1, "Calling publish success for client %s", command->client->c->clientID);
(*(command->command.onSuccess5))(command->command.context, &data);
}
} }
else else
{ {
...@@ -1382,11 +1431,21 @@ static int MQTTAsync_processCommand(void) ...@@ -1382,11 +1431,21 @@ static int MQTTAsync_processCommand(void)
MQTTAsync_failureData data; MQTTAsync_failureData data;
data.token = 0; data.token = 0;
data.code = -2; data.code = MQTTASYNC_OPERATION_INCOMPLETE;
data.message = NULL; data.message = NULL;
Log(TRACE_MIN, -1, "Calling connect failure for client %s", command->client->c->clientID); Log(TRACE_MIN, -1, "Calling connect failure for client %s", command->client->c->clientID);
(*(command->client->connect.onFailure))(command->client->connect.context, &data); (*(command->client->connect.onFailure))(command->client->connect.context, &data);
} }
else if (command->client->connect.onFailure5)
{
MQTTAsync_failureData5 data;
data.token = 0;
data.code = MQTTASYNC_OPERATION_INCOMPLETE;
data.message = NULL;
Log(TRACE_MIN, -1, "Calling connect failure for client %s", command->client->c->clientID);
(*(command->client->connect.onFailure5))(command->client->connect.context, &data);
}
} }
MQTTAsync_checkDisconnect(command->client, &command->command); MQTTAsync_checkDisconnect(command->client, &command->command);
} }
...@@ -1446,6 +1505,11 @@ static int MQTTAsync_processCommand(void) ...@@ -1446,6 +1505,11 @@ static int MQTTAsync_processCommand(void)
Log(TRACE_MIN, -1, "Calling command failure for client %s", command->client->c->clientID); Log(TRACE_MIN, -1, "Calling command failure for client %s", command->client->c->clientID);
(*(command->command.onFailure))(command->command.context, NULL); (*(command->command.onFailure))(command->command.context, NULL);
} }
else if (command->command.onFailure5)
{
Log(TRACE_MIN, -1, "Calling command failure for client %s", command->client->c->clientID);
(*(command->command.onFailure5))(command->command.context, NULL);
}
if (command->command.type == CONNECT) if (command->command.type == CONNECT)
{ {
command->client->connect = command->command; command->client->connect = command->command;
...@@ -1505,6 +1569,16 @@ static void nextOrClose(MQTTAsyncs* m, int rc, char* message) ...@@ -1505,6 +1569,16 @@ static void nextOrClose(MQTTAsyncs* m, int rc, char* message)
Log(TRACE_MIN, -1, "Calling connect failure for client %s", m->c->clientID); Log(TRACE_MIN, -1, "Calling connect failure for client %s", m->c->clientID);
(*(m->connect.onFailure))(m->connect.context, &data); (*(m->connect.onFailure))(m->connect.context, &data);
} }
else if (m->connect.onFailure5)
{
MQTTAsync_failureData5 data = MQTTAsync_failureData5_initializer;
data.token = 0;
data.code = rc;
data.message = message;
Log(TRACE_MIN, -1, "Calling connect failure for client %s", m->c->clientID);
(*(m->connect.onFailure5))(m->connect.context, &data);
}
MQTTAsync_startConnectRetry(m); MQTTAsync_startConnectRetry(m);
} }
} }
...@@ -1558,6 +1632,12 @@ static void MQTTAsync_checkTimeouts(void) ...@@ -1558,6 +1632,12 @@ static void MQTTAsync_checkTimeouts(void)
MQTTPacket_name(com->command.type), m->c->clientID); MQTTPacket_name(com->command.type), m->c->clientID);
(*(com->command.onFailure))(com->command.context, NULL); (*(com->command.onFailure))(com->command.context, NULL);
} }
else if (com->command.onFailure5)
{
Log(TRACE_MIN, -1, "Calling %s failure for client %s",
MQTTPacket_name(com->command.type), m->c->clientID);
(*(com->command.onFailure5))(com->command.context, NULL);
}
timed_out_count++; timed_out_count++;
} }
} }
...@@ -1671,6 +1751,18 @@ static void MQTTAsync_removeResponsesAndCommands(MQTTAsyncs* m) ...@@ -1671,6 +1751,18 @@ static void MQTTAsync_removeResponsesAndCommands(MQTTAsyncs* m)
MQTTPacket_name(command->command.type), m->c->clientID); MQTTPacket_name(command->command.type), m->c->clientID);
(*(command->command.onFailure))(command->command.context, &data); (*(command->command.onFailure))(command->command.context, &data);
} }
else if (command->command.onFailure5)
{
MQTTAsync_failureData5 data = MQTTAsync_failureData5_initializer;
data.token = command->command.token;
data.code = MQTTASYNC_OPERATION_INCOMPLETE; /* interrupted return code */
data.message = NULL;
Log(TRACE_MIN, -1, "Calling %s failure for client %s",
MQTTPacket_name(command->command.type), m->c->clientID);
(*(command->command.onFailure5))(command->command.context, &data);
}
MQTTAsync_freeCommand1(command); MQTTAsync_freeCommand1(command);
count++; count++;
...@@ -1703,6 +1795,18 @@ static void MQTTAsync_removeResponsesAndCommands(MQTTAsyncs* m) ...@@ -1703,6 +1795,18 @@ static void MQTTAsync_removeResponsesAndCommands(MQTTAsyncs* m)
MQTTPacket_name(command->command.type), m->c->clientID); MQTTPacket_name(command->command.type), m->c->clientID);
(*(command->command.onFailure))(command->command.context, &data); (*(command->command.onFailure))(command->command.context, &data);
} }
else if (command->command.onFailure5)
{
MQTTAsync_failureData5 data = MQTTAsync_failureData5_initializer;
data.token = command->command.token;
data.code = MQTTASYNC_OPERATION_INCOMPLETE; /* interrupted return code */
data.message = NULL;
Log(TRACE_MIN, -1, "Calling %s failure for client %s",
MQTTPacket_name(command->command.type), m->c->clientID);
(*(command->command.onFailure5))(command->command.context, &data);
}
MQTTAsync_freeCommand(command); MQTTAsync_freeCommand(command);
count++; count++;
...@@ -3283,6 +3387,20 @@ static MQTTPacket* MQTTAsync_cycle(int* sock, unsigned long timeout, int* rc) ...@@ -3283,6 +3387,20 @@ static MQTTPacket* MQTTAsync_cycle(int* sock, unsigned long timeout, int* rc)
Log(TRACE_MIN, -1, "Calling publish success for client %s", m->c->clientID); Log(TRACE_MIN, -1, "Calling publish success for client %s", m->c->clientID);
(*(command->command.onSuccess))(command->command.context, &data); (*(command->command.onSuccess))(command->command.context, &data);
} }
else if (command->command.onSuccess5)
{
MQTTAsync_successData5 data = MQTTAsync_successData5_initializer;
data.token = command->command.token;
data.alt.pub.destinationName = command->command.details.pub.destinationName;
data.alt.pub.message.payload = command->command.details.pub.payload;
data.alt.pub.message.payloadlen = command->command.details.pub.payloadlen;
data.alt.pub.message.qos = command->command.details.pub.qos;
data.alt.pub.message.retained = command->command.details.pub.retained;
data.props = command->command.properties;
Log(TRACE_MIN, -1, "Calling publish success for client %s", m->c->clientID);
(*(command->command.onSuccess5))(command->command.context, &data);
}
MQTTAsync_freeCommand(command); MQTTAsync_freeCommand(command);
break; break;
} }
......
...@@ -416,11 +416,13 @@ typedef struct ...@@ -416,11 +416,13 @@ typedef struct
enum MQTTReasonCodes reasonCode; enum MQTTReasonCodes reasonCode;
/** The MQTT properties on the ack, if any. */ /** The MQTT properties on the ack, if any. */
MQTTProperties properties; MQTTProperties properties;
/** A numeric code identifying the MQTT client library error. */
int code;
/** Optional further text explaining the error. Can be NULL. */ /** Optional further text explaining the error. Can be NULL. */
const char *message; const char *message;
} MQTTAsync_failureData5; } MQTTAsync_failureData5;
#define MQTTAsync_failureData5_initializer {{'M', 'Q', 'F', 'D'}, 0, 0, SUCCESS, MQTTProperties_initializer, NULL} #define MQTTAsync_failureData5_initializer {{'M', 'Q', 'F', 'D'}, 0, 0, SUCCESS, MQTTProperties_initializer, 0, NULL}
/** The data returned on completion of a successful API call in the response callback onSuccess. */ /** The data returned on completion of a successful API call in the response callback onSuccess. */
typedef struct typedef struct
...@@ -959,6 +961,10 @@ typedef struct ...@@ -959,6 +961,10 @@ typedef struct
int len; /**< binary password length */ int len; /**< binary password length */
const void* data; /**< binary password data */ const void* data; /**< binary password data */
} binarypwd; } binarypwd;
/*
* MQTT V5 clean start flag. Only clears state at the beginning of the session.
*/
int cleanstart;
/** /**
* MQTT V5 properties for connect * MQTT V5 properties for connect
*/ */
...@@ -983,7 +989,7 @@ typedef struct ...@@ -983,7 +989,7 @@ typedef struct
#define MQTTAsync_connectOptions_initializer { {'M', 'Q', 'T', 'C'}, 6, 60, 1, 10, NULL, NULL, NULL, 30, 0,\ #define MQTTAsync_connectOptions_initializer { {'M', 'Q', 'T', 'C'}, 6, 60, 1, 10, NULL, NULL, NULL, 30, 0,\
NULL, NULL, NULL, NULL, 0, NULL, 0, 0, 1, 60, {0, NULL}, NULL, NULL, NULL, NULL} NULL, NULL, NULL, NULL, 0, NULL, 0, 0, 1, 60, {0, NULL}, 0, NULL, NULL, NULL, NULL}
/** /**
* This function attempts to connect a previously-created client (see * This function attempts to connect a previously-created client (see
...@@ -1179,9 +1185,6 @@ DLLExport int MQTTAsync_unsubscribeMany(MQTTAsync handle, int count, char* const ...@@ -1179,9 +1185,6 @@ DLLExport int MQTTAsync_unsubscribeMany(MQTTAsync handle, int count, char* const
DLLExport int MQTTAsync_send(MQTTAsync handle, const char* destinationName, int payloadlen, void* payload, int qos, DLLExport int MQTTAsync_send(MQTTAsync handle, const char* destinationName, int payloadlen, void* payload, int qos,
int retained, MQTTAsync_responseOptions* response); int retained, MQTTAsync_responseOptions* response);
DLLExport int MQTTAsync_send5(MQTTAsync handle, const char* destinationName, int payloadlen, void* payload, int qos,
int retained, MQTTProperties* props, MQTTAsync_responseOptions* response);
/** /**
* This function attempts to publish a message to a given topic (see also * This function attempts to publish a message to a given topic (see also
......
...@@ -66,7 +66,7 @@ int MQTTPacket_send_connect(Clients* client, int MQTTVersion, ...@@ -66,7 +66,7 @@ int MQTTPacket_send_connect(Clients* client, int MQTTVersion,
if (MQTTVersion >= MQTTVERSION_5) if (MQTTVersion >= MQTTVERSION_5)
{ {
len += MQTTProperties_len(connectProperties); len += MQTTProperties_len(connectProperties);
if (client->will && willProperties) if (client->will)
len += MQTTProperties_len(willProperties); len += MQTTProperties_len(willProperties);
} }
......
...@@ -289,8 +289,50 @@ ADD_TEST( ...@@ -289,8 +289,50 @@ ADD_TEST(
COMMAND test45 "--test_no" "1" "--connection" ${MQTT_TEST_BROKER} COMMAND test45 "--test_no" "1" "--connection" ${MQTT_TEST_BROKER}
) )
ADD_TEST(
NAME test45-2-connect-timeout
COMMAND test45 "--test_no" "2" "--connection" ${MQTT_TEST_BROKER}
)
ADD_TEST(
NAME test45-3-multiple-client-objs-simultaneous-working
COMMAND test45 "--test_no" "3" "--connection" ${MQTT_TEST_BROKER}
)
ADD_TEST(
NAME test45-4-send-receive-big-messages
COMMAND test45 "--test_no" "4" "--connection" ${MQTT_TEST_BROKER}
)
ADD_TEST(
NAME test45-5-connack-return-codes
COMMAND test45 "--test_no" "5" "--connection" ${MQTT_TEST_BROKER}
)
ADD_TEST(
NAME test45-6-ha-connections
COMMAND test45 "--test_no" "6" "--connection" ${MQTT_TEST_BROKER}
)
ADD_TEST(
NAME test45-7-pending-tokens
COMMAND test45 "--test_no" "7" "--connection" ${MQTT_TEST_BROKER}
)
ADD_TEST(
NAME test45-8-incomplete-commands-requests
COMMAND test45 "--test_no" "8" "--connection" ${MQTT_TEST_BROKER}
)
SET_TESTS_PROPERTIES( SET_TESTS_PROPERTIES(
test45-1-basic-connect-subscribe-receive test45-1-basic-connect-subscribe-receive
test45-2-connect-timeout
test45-3-multiple-client-objs-simultaneous-working
test45-4-send-receive-big-messages
test45-5-connack-return-codes
test45-6-ha-connections
test45-7-pending-tokens
test45-8-incomplete-commands-requests
PROPERTIES TIMEOUT 540 PROPERTIES TIMEOUT 540
) )
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment