Commit 7ea13339 authored by Ian Craggs's avatar Ian Craggs

MQTTClient v5 specific tests. Receive disconnect #469. Client topic aliases #472

parent fcef9b5d
...@@ -90,7 +90,7 @@ SYNC_SAMPLES = ${addprefix ${blddir}/samples/,${SAMPLE_FILES_C}} ...@@ -90,7 +90,7 @@ SYNC_SAMPLES = ${addprefix ${blddir}/samples/,${SAMPLE_FILES_C}}
SAMPLE_FILES_A = paho_c_pub paho_c_sub MQTTAsync_subscribe MQTTAsync_publish SAMPLE_FILES_A = paho_c_pub paho_c_sub MQTTAsync_subscribe MQTTAsync_publish
ASYNC_SAMPLES = ${addprefix ${blddir}/samples/,${SAMPLE_FILES_A}} ASYNC_SAMPLES = ${addprefix ${blddir}/samples/,${SAMPLE_FILES_A}}
TEST_FILES_C = test1 test15 test2 sync_client_test test_mqtt4sync TEST_FILES_C = test1 test15 test2 sync_client_test test_mqtt4sync test10
SYNC_TESTS = ${addprefix ${blddir}/test/,${TEST_FILES_C}} SYNC_TESTS = ${addprefix ${blddir}/test/,${TEST_FILES_C}}
TEST_FILES_CS = test3 TEST_FILES_CS = test3
......
...@@ -48,6 +48,7 @@ SET(common_src ...@@ -48,6 +48,7 @@ SET(common_src
Heap.c Heap.c
LinkedList.c LinkedList.c
MQTTProperties.c MQTTProperties.c
MQTTReasonCodes.c
Base64.c Base64.c
SHA1.c SHA1.c
WebSocket.c WebSocket.c
......
...@@ -205,6 +205,12 @@ typedef struct ...@@ -205,6 +205,12 @@ typedef struct
MQTTClient_deliveryComplete* dc; MQTTClient_deliveryComplete* dc;
void* context; void* context;
MQTTClient_disconnected* disconnected;
void* disconnected_context; /* the context to be associated with the disconnected callback*/
MQTTClient_authHandle* auth_handle;
void* auth_handle_context; /* the context to be associated with the authHandle callback*/
sem_type connect_sem; sem_type connect_sem;
int rc; /* getsockopt return code in connect */ int rc; /* getsockopt return code in connect */
sem_type connack_sem; sem_type connack_sem;
...@@ -214,6 +220,13 @@ typedef struct ...@@ -214,6 +220,13 @@ typedef struct
} MQTTClients; } MQTTClients;
struct props_rc_parms
{
MQTTClients* m;
MQTTProperties* properties;
enum MQTTReasonCodes reasonCode;
};
void MQTTClient_sleep(long milliseconds) void MQTTClient_sleep(long milliseconds)
{ {
FUNC_ENTRY; FUNC_ENTRY;
...@@ -546,6 +559,18 @@ void MQTTClient_free(void* memory) ...@@ -546,6 +559,18 @@ void MQTTClient_free(void* memory)
} }
DLLExport void MQTTResponse_free(MQTTResponse response)
{
FUNC_ENTRY;
if (response.properties)
{
MQTTProperties_free(response.properties);
free(response.properties);
}
FUNC_EXIT;
}
static int MQTTClient_deliverMessage(int rc, MQTTClients* m, char** topicName, int* topicLen, MQTTClient_message** message) static int MQTTClient_deliverMessage(int rc, MQTTClients* m, char** topicName, int* topicLen, MQTTClient_message** message)
{ {
qEntry* qe = (qEntry*)(m->c->messageQueue->first->content); qEntry* qe = (qEntry*)(m->c->messageQueue->first->content);
...@@ -594,6 +619,81 @@ static thread_return_type WINAPI connectionLost_call(void* context) ...@@ -594,6 +619,81 @@ static thread_return_type WINAPI connectionLost_call(void* context)
} }
int MQTTClient_setDisconnected(MQTTClient handle, void* context, MQTTClient_disconnected* disconnected)
{
int rc = MQTTCLIENT_SUCCESS;
MQTTClients* m = handle;
FUNC_ENTRY;
Thread_lock_mutex(mqttclient_mutex);
if (m == NULL || m->c->connect_state != NOT_IN_PROGRESS)
rc = MQTTCLIENT_FAILURE;
else
{
m->disconnected_context = context;
m->disconnected = disconnected;
}
Thread_unlock_mutex(mqttclient_mutex);
FUNC_EXIT_RC(rc);
return rc;
}
/**
* Wrapper function to call disconnected on a separate thread. A separate thread is needed to allow the
* disconnected function to make API calls (e.g. connect)
* @param context a pointer to the relevant client
* @return thread_return_type standard thread return value - not used here
*/
static thread_return_type WINAPI call_disconnected(void* context)
{
struct props_rc_parms* pr = (struct props_rc_parms*)context;
(*(pr->m->disconnected))(pr->m->disconnected_context, pr->properties, pr->reasonCode);
MQTTProperties_free(pr->properties);
return 0;
}
int MQTTClient_setAuthHandle(MQTTClient handle, void* context, MQTTClient_authHandle* auth_handle)
{
int rc = MQTTCLIENT_SUCCESS;
MQTTClients* m = handle;
FUNC_ENTRY;
Thread_lock_mutex(mqttclient_mutex);
if (m == NULL || m->c->connect_state != NOT_IN_PROGRESS)
rc = MQTTCLIENT_FAILURE;
else
{
m->auth_handle_context = context;
m->auth_handle = auth_handle;
}
Thread_unlock_mutex(mqttclient_mutex);
FUNC_EXIT_RC(rc);
return rc;
}
/**
* Wrapper function to call authHandle on a separate thread. A separate thread is needed to allow the
* disconnected function to make API calls (e.g. MQTTClient_auth)
* @param context a pointer to the relevant client
* @return thread_return_type standard thread return value - not used here
*/
static thread_return_type WINAPI call_auth_handle(void* context)
{
struct props_rc_parms* pr = (struct props_rc_parms*)context;
(*(pr->m->auth_handle))(pr->m->auth_handle_context, pr->properties, pr->reasonCode);
return 0;
}
/* This is the thread function that handles the calling of callback functions if set */ /* This is the thread function that handles the calling of callback functions if set */
static thread_return_type WINAPI MQTTClient_run(void* n) static thread_return_type WINAPI MQTTClient_run(void* n)
{ {
...@@ -699,6 +799,33 @@ static thread_return_type WINAPI MQTTClient_run(void* n) ...@@ -699,6 +799,33 @@ static thread_return_type WINAPI MQTTClient_run(void* n)
m->pack = pack; m->pack = pack;
Thread_post_sem(m->unsuback_sem); Thread_post_sem(m->unsuback_sem);
} }
else if (m->c->MQTTVersion >= MQTTVERSION_5)
{
if (pack->header.bits.type == DISCONNECT && m->disconnected)
{
struct props_rc_parms dp;
Ack* disc = (Ack*)pack;
dp.m = m;
dp.properties = &disc->properties;
dp.reasonCode = disc->rc;
free(pack);
Log(TRACE_MIN, -1, "Calling disconnected for client %s", m->c->clientID);
Thread_start(call_disconnected, &dp);
}
if (pack->header.bits.type == AUTH && m->auth_handle)
{
struct props_rc_parms dp;
Ack* disc = (Ack*)pack;
dp.m = m;
dp.properties = &disc->properties;
dp.reasonCode = disc->rc;
free(pack);
Log(TRACE_MIN, -1, "Calling auth_handle for client %s", m->c->clientID);
Thread_start(call_auth_handle, &dp);
}
}
} }
else if (m->c->connect_state == TCP_IN_PROGRESS && !Thread_check_sem(m->connect_sem)) else if (m->c->connect_state == TCP_IN_PROGRESS && !Thread_check_sem(m->connect_sem))
{ {
...@@ -1112,7 +1239,10 @@ static MQTTResponse MQTTClient_connectURIVersion(MQTTClient handle, MQTTClient_c ...@@ -1112,7 +1239,10 @@ static MQTTResponse MQTTClient_connectURIVersion(MQTTClient handle, MQTTClient_c
rc = MQTTCLIENT_DISCONNECTED; rc = MQTTCLIENT_DISCONNECTED;
} }
if (m->c->MQTTVersion == MQTTVERSION_5) if (m->c->MQTTVersion == MQTTVERSION_5)
resp.properties = &connack->properties; {
resp.properties = malloc(sizeof(MQTTProperties));
*resp.properties = MQTTProperties_copy(&connack->properties);
}
} }
MQTTPacket_freeConnack(connack); MQTTPacket_freeConnack(connack);
m->pack = NULL; m->pack = NULL;
...@@ -1930,7 +2060,7 @@ MQTTResponse MQTTClient_publishMessage5(MQTTClient handle, const char* topicName ...@@ -1930,7 +2060,7 @@ MQTTResponse MQTTClient_publishMessage5(MQTTClient handle, const char* topicName
goto exit; goto exit;
} }
if (message->struct_version == 1) if (message->struct_version >= 1)
props = &message->properties; props = &message->properties;
rc = MQTTClient_publish5(handle, topicName, message->payloadlen, message->payload, rc = MQTTClient_publish5(handle, topicName, message->payloadlen, message->payload,
......
...@@ -414,6 +414,67 @@ DLLExport int MQTTClient_setCallbacks(MQTTClient handle, void* context, MQTTClie ...@@ -414,6 +414,67 @@ DLLExport int MQTTClient_setCallbacks(MQTTClient handle, void* context, MQTTClie
MQTTClient_messageArrived* ma, MQTTClient_deliveryComplete* dc); MQTTClient_messageArrived* ma, MQTTClient_deliveryComplete* dc);
/**
* 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.
* @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.
* 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.
* @param handle A valid client handle from a successful call to
* MQTTAsync_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
* function. NULL removes the callback setting.
* @return ::MQTTASYNC_SUCCESS if the callbacks were correctly set,
* ::MQTTASYNC_FAILURE if an error occurred.
*/
DLLExport int MQTTClient_setDisconnected(MQTTClient handle, void* context, MQTTClient_disconnected* co);
/**
* 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.
* @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.
* Currently, <i>cause</i> is always set to NULL.
*/
typedef void MQTTClient_authHandle(void* context, MQTTProperties* properties,
enum MQTTReasonCodes reasonCode);
/**
* Sets the MQTTClient_authHandle() callback function for a client.
* @param handle A valid client handle from a successful call to
* MQTTAsync_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
* function. NULL removes the callback setting.
* @return ::MQTTASYNC_SUCCESS if the callbacks were correctly set,
* ::MQTTASYNC_FAILURE if an error occurred.
*/
DLLExport int MQTTClient_setAuthHandle(MQTTClient handle, void* context, MQTTClient_authHandle* ah);
/** /**
* This function creates an MQTT client ready for connection to the * This function creates an MQTT client ready for connection to the
* specified server and using the specified persistent storage (see * specified server and using the specified persistent storage (see
...@@ -785,6 +846,8 @@ typedef struct MQTTResponse ...@@ -785,6 +846,8 @@ typedef struct MQTTResponse
MQTTProperties* properties; /* optional */ MQTTProperties* properties; /* optional */
} MQTTResponse; } MQTTResponse;
DLLExport void MQTTResponse_free(MQTTResponse response);
DLLExport MQTTResponse MQTTClient_connect5(MQTTClient handle, MQTTClient_connectOptions* options, DLLExport MQTTResponse MQTTClient_connect5(MQTTClient handle, MQTTClient_connectOptions* options,
MQTTProperties* connectProperties, MQTTProperties* willProperties); MQTTProperties* connectProperties, MQTTProperties* willProperties);
......
...@@ -85,7 +85,8 @@ pf new_packets[] = ...@@ -85,7 +85,8 @@ pf new_packets[] =
MQTTPacket_unsuback, /**< UNSUBACK */ MQTTPacket_unsuback, /**< UNSUBACK */
MQTTPacket_header_only, /**< PINGREQ */ MQTTPacket_header_only, /**< PINGREQ */
MQTTPacket_header_only, /**< PINGRESP */ MQTTPacket_header_only, /**< PINGRESP */
MQTTPacket_header_only /**< DISCONNECT */ MQTTPacket_ack, /**< DISCONNECT */
MQTTPacket_ack /**< AUTH */
}; };
...@@ -132,7 +133,9 @@ void* MQTTPacket_Factory(int MQTTVersion, networkHandles* net, int* error) ...@@ -132,7 +133,9 @@ void* MQTTPacket_Factory(int MQTTVersion, networkHandles* net, int* error)
else else
{ {
ptype = header.bits.type; ptype = header.bits.type;
if (ptype < CONNECT || ptype > DISCONNECT || new_packets[ptype] == NULL) if (ptype < CONNECT || (MQTTVersion < MQTTVERSION_5 && ptype >= DISCONNECT) ||
(MQTTVersion >= MQTTVERSION_5 && ptype > AUTH) ||
new_packets[ptype] == NULL)
Log(TRACE_MIN, 2, NULL, ptype); Log(TRACE_MIN, 2, NULL, ptype);
else else
{ {
...@@ -723,7 +726,8 @@ void* MQTTPacket_ack(int MQTTVersion, unsigned char aHeader, char* data, size_t ...@@ -723,7 +726,8 @@ void* MQTTPacket_ack(int MQTTVersion, unsigned char aHeader, char* data, size_t
FUNC_ENTRY; FUNC_ENTRY;
pack->MQTTVersion = MQTTVersion; pack->MQTTVersion = MQTTVersion;
pack->header.byte = aHeader; pack->header.byte = aHeader;
pack->msgId = readInt(&curdata); if (pack->header.bits.type != DISCONNECT)
pack->msgId = readInt(&curdata);
if (MQTTVersion >= MQTTVERSION_5) if (MQTTVersion >= MQTTVERSION_5)
{ {
MQTTProperties props = MQTTProperties_initializer; MQTTProperties props = MQTTProperties_initializer;
...@@ -736,8 +740,6 @@ void* MQTTPacket_ack(int MQTTVersion, unsigned char aHeader, char* data, size_t ...@@ -736,8 +740,6 @@ void* MQTTPacket_ack(int MQTTVersion, unsigned char aHeader, char* data, size_t
if (datalen > 3) if (datalen > 3)
{ {
pack->properties.max_count = 10;
pack->properties.array = malloc(sizeof(MQTTProperty) * pack->properties.max_count);
if (MQTTProperties_read(&pack->properties, &curdata, enddata) != 1) if (MQTTProperties_read(&pack->properties, &curdata, enddata) != 1)
{ {
free(pack); free(pack);
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
struct nameToType static struct nameToType
{ {
enum PropertyNames name; enum PropertyNames name;
enum PropertyTypes type; enum PropertyTypes type;
......
...@@ -163,6 +163,7 @@ int MQTTProtocol_startPublish(Clients* pubclient, Publish* publish, int qos, int ...@@ -163,6 +163,7 @@ int MQTTProtocol_startPublish(Clients* pubclient, Publish* publish, int qos, int
p.payload = (*mm)->publish->payload; p.payload = (*mm)->publish->payload;
p.topic = (*mm)->publish->topic; p.topic = (*mm)->publish->topic;
p.properties = (*mm)->properties; p.properties = (*mm)->properties;
p.MQTTVersion = (*mm)->MQTTVersion;
} }
rc = MQTTProtocol_startPublishCommon(pubclient, &p, qos, retained); rc = MQTTProtocol_startPublishCommon(pubclient, &p, qos, retained);
FUNC_EXIT_RC(rc); FUNC_EXIT_RC(rc);
......
/*******************************************************************************
* Copyright (c) 2017, 2018 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Ian Craggs - initial API and implementation and/or initial documentation
*******************************************************************************/
#include "MQTTReasonCodes.h"
#include "Heap.h"
#include "StackTrace.h"
#include <memory.h>
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
static struct {
enum MQTTReasonCodes value;
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"}
};
const char* MQTTReasonCodeString(enum MQTTReasonCodes value)
{
int i = 0;
const char* result = NULL;
for (i = 0; i < ARRAY_SIZE(nameToString); ++i)
{
if (nameToString[i].value == value)
{
result = nameToString[i].name;
break;
}
}
return result;
}
...@@ -58,11 +58,21 @@ enum MQTTReasonCodes { ...@@ -58,11 +58,21 @@ enum MQTTReasonCodes {
QOS_NOT_SUPPORTED = 155, QOS_NOT_SUPPORTED = 155,
USE_ANOTHER_SERVER = 156, USE_ANOTHER_SERVER = 156,
SERVER_MOVED = 157, SERVER_MOVED = 157,
SHARED_SUBSCRIPTION_NOT_SUPPORTED = 158, SHARED_SUBSCRIPTIONS_NOT_SUPPORTED = 158,
CONNECTION_RATE_EXCEEDED = 159, CONNECTION_RATE_EXCEEDED = 159,
MAXIMUM_CONNECT_TIME = 160, MAXIMUM_CONNECT_TIME = 160,
SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED = 161, SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED = 161,
WILDCARD_SUBSCRIPTION_NOT_SUPPORTED = 162 WILDCARD_SUBSCRIPTIONS_NOT_SUPPORTED = 162
}; };
#if defined(WIN32) || defined(WIN64)
#define DLLImport __declspec(dllimport)
#define DLLExport __declspec(dllexport)
#else
#define DLLImport extern
#define DLLExport __attribute__ ((visibility ("default")))
#endif
DLLExport const char* MQTTReasonCodeString(enum MQTTReasonCodes);
#endif #endif
...@@ -564,6 +564,26 @@ SET_TESTS_PROPERTIES( ...@@ -564,6 +564,26 @@ SET_TESTS_PROPERTIES(
PROPERTIES TIMEOUT 540 PROPERTIES TIMEOUT 540
) )
ADD_EXECUTABLE(
test10
test10.c
)
TARGET_LINK_LIBRARIES(
test10
paho-mqtt3c
)
ADD_TEST(
NAME test10-1-client_topic_aliases
COMMAND "test10" "--test_no" "1" "--connection" ${MQTT_TEST_BROKER} "--proxy_connection" ${MQTT_TEST_PROXY}
)
SET_TESTS_PROPERTIES(
test10-1-client_topic_aliases
PROPERTIES TIMEOUT 540
)
ADD_EXECUTABLE( ADD_EXECUTABLE(
test_issue373 test_issue373
test_issue373.c test_issue373.c
......
This diff is collapsed.
...@@ -58,9 +58,9 @@ struct Options ...@@ -58,9 +58,9 @@ struct Options
int iterations; int iterations;
} options = } options =
{ {
"tcp://iot.eclipse.org:1883",
NULL,
"tcp://localhost:1883", "tcp://localhost:1883",
NULL,
"tcp://localhost:1884",
0, 0,
0, 0,
0, 0,
...@@ -291,7 +291,7 @@ void test1_sendAndReceive(MQTTClient* c, int qos, char* test_topic) ...@@ -291,7 +291,7 @@ void test1_sendAndReceive(MQTTClient* c, int qos, char* test_topic)
char* topicName = NULL; char* topicName = NULL;
int topicLen; int topicLen;
int i = 0; int i = 0;
int iterations = 1; //50; int iterations = 50;
int rc; int rc;
MQTTResponse resp; MQTTResponse resp;
MQTTProperty property; MQTTProperty property;
...@@ -463,7 +463,7 @@ int test1(struct Options options) ...@@ -463,7 +463,7 @@ int test1(struct Options options)
if (response.properties) if (response.properties)
{ {
logProperties(response.properties); logProperties(response.properties);
MQTTProperties_free(response.properties); MQTTResponse_free(response);
} }
subopts.retainAsPublished = 1; subopts.retainAsPublished = 1;
...@@ -508,6 +508,7 @@ int test1(struct Options options) ...@@ -508,6 +508,7 @@ int test1(struct Options options)
/* Just to make sure we can connect again */ /* Just to make sure we can connect again */
response = MQTTClient_connect5(c, &opts, NULL, NULL); response = MQTTClient_connect5(c, &opts, NULL, NULL);
assert("Connect successful", response.reasonCode == MQTTCLIENT_SUCCESS, "rc was %d", response.reasonCode); 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, SUCCESS, &props);
assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); assert("Disconnect successful", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc);
...@@ -670,7 +671,9 @@ int test2(struct Options options) ...@@ -670,7 +671,9 @@ int test2(struct Options options)
MyLog(LOGA_DEBUG, "Connecting"); MyLog(LOGA_DEBUG, "Connecting");
response = MQTTClient_connect5(c, &opts, &props, &willProps); response = MQTTClient_connect5(c, &opts, &props, &willProps);
assert("Good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d", rc); assert("Good rc from connect", response.reasonCode == MQTTCLIENT_SUCCESS,
"rc was %d", response.reasonCode);
MQTTResponse_free(response);
if (rc != MQTTCLIENT_SUCCESS) if (rc != MQTTCLIENT_SUCCESS)
goto exit; goto exit;
...@@ -719,6 +722,7 @@ int test3(struct Options options) ...@@ -719,6 +722,7 @@ int test3(struct Options options)
MQTTClient c; MQTTClient c;
MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer; MQTTClient_connectOptions opts = MQTTClient_connectOptions_initializer;
MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer; MQTTClient_willOptions wopts = MQTTClient_willOptions_initializer;
MQTTResponse response;
fprintf(xml, "<testcase classname=\"test1\" name=\"connack return codes\""); fprintf(xml, "<testcase classname=\"test1\" name=\"connack return codes\"");
global_start_time = start_clock(); global_start_time = start_clock();
...@@ -756,8 +760,9 @@ int test3(struct Options options) ...@@ -756,8 +760,9 @@ int test3(struct Options options)
opts.will->qos = 1; opts.will->qos = 1;
opts.will->retained = 0; opts.will->retained = 0;
opts.will->topicName = "will topic";*/ opts.will->topicName = "will topic";*/
rc = MQTTClient_connect(c, &opts); response = MQTTClient_connect5(c, &opts, NULL, NULL);
//assert("Not authorized", rc == 5, "rc was %d\n", rc); //assert("Not authorized", rc == 5, "rc was %d\n", rc);
MQTTResponse_free(response);
#if 0 #if 0
/* successful connection (RC = 0) */ /* successful connection (RC = 0) */
...@@ -825,6 +830,7 @@ int test4_run(int qos) ...@@ -825,6 +830,7 @@ int test4_run(int qos)
response = MQTTClient_connect5(c, &opts, &props, NULL); response = MQTTClient_connect5(c, &opts, &props, NULL);
assert("Good rc from connect", response.reasonCode == MQTTCLIENT_SUCCESS, assert("Good rc from connect", response.reasonCode == MQTTCLIENT_SUCCESS,
"rc was %d", response.reasonCode); "rc was %d", response.reasonCode);
MQTTResponse_free(response);
if (response.reasonCode != MQTTCLIENT_SUCCESS) if (response.reasonCode != MQTTCLIENT_SUCCESS)
return -1; return -1;
...@@ -879,6 +885,7 @@ int test4_run(int qos) ...@@ -879,6 +885,7 @@ int test4_run(int qos)
opts.cleansession = 0; opts.cleansession = 0;
response = MQTTClient_connect5(c, &opts, NULL, NULL); response = MQTTClient_connect5(c, &opts, NULL, NULL);
assert("Good rc from connect", response.reasonCode == MQTTCLIENT_SUCCESS, "rc was %d", response.reasonCode); assert("Good rc from connect", response.reasonCode == MQTTCLIENT_SUCCESS, "rc was %d", response.reasonCode);
MQTTResponse_free(response);
if (response.reasonCode != MQTTCLIENT_SUCCESS) if (response.reasonCode != MQTTCLIENT_SUCCESS)
return -1; return -1;
...@@ -986,6 +993,7 @@ int test5(struct Options options) ...@@ -986,6 +993,7 @@ int test5(struct Options options)
MyLog(LOGA_DEBUG, "Connecting"); MyLog(LOGA_DEBUG, "Connecting");
response = MQTTClient_connect5(c, &opts, &props, NULL); response = MQTTClient_connect5(c, &opts, &props, NULL);
assert("Good rc from connect", response.reasonCode == MQTTCLIENT_SUCCESS, "rc was %d", response.reasonCode); assert("Good rc from connect", response.reasonCode == MQTTCLIENT_SUCCESS, "rc was %d", response.reasonCode);
MQTTResponse_free(response);
if (response.reasonCode != MQTTCLIENT_SUCCESS) if (response.reasonCode != MQTTCLIENT_SUCCESS)
{ {
MQTTClient_destroy(&c); MQTTClient_destroy(&c);
...@@ -1101,6 +1109,7 @@ int test6(struct Options options) ...@@ -1101,6 +1109,7 @@ int test6(struct Options options)
/* Connect to the broker */ /* Connect to the broker */
response = MQTTClient_connect5(test6_c1, &opts, NULL, NULL); response = MQTTClient_connect5(test6_c1, &opts, NULL, NULL);
assert("good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc); assert("good rc from connect", rc == MQTTCLIENT_SUCCESS, "rc was %d\n", rc);
MQTTResponse_free(response);
if (rc != MQTTCLIENT_SUCCESS) if (rc != MQTTCLIENT_SUCCESS)
goto exit; goto exit;
...@@ -1117,6 +1126,7 @@ int test6(struct Options options) ...@@ -1117,6 +1126,7 @@ int test6(struct Options options)
opts2.cleansession = 1; opts2.cleansession = 1;
MyLog(LOGA_INFO, "Connecting Client_2 ..."); MyLog(LOGA_INFO, "Connecting Client_2 ...");
response = MQTTClient_connect5(test6_c2, &opts2, NULL, NULL); response = MQTTClient_connect5(test6_c2, &opts2, NULL, NULL);
MQTTResponse_free(response);
assert("Good rc from connect", response.reasonCode == MQTTCLIENT_SUCCESS, "rc was %d\n", response.reasonCode); 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); response = MQTTClient_subscribe5(test6_c2, test6_will_topic, 2, NULL, NULL);
...@@ -1211,6 +1221,7 @@ int test6a(struct Options options) ...@@ -1211,6 +1221,7 @@ int test6a(struct Options options)
response = MQTTClient_connect5(test6_c1, &opts, NULL, NULL); response = MQTTClient_connect5(test6_c1, &opts, NULL, NULL);
assert("good rc from connect", response.reasonCode == MQTTCLIENT_SUCCESS, assert("good rc from connect", response.reasonCode == MQTTCLIENT_SUCCESS,
"rc was %d\n", response.reasonCode); "rc was %d\n", response.reasonCode);
MQTTResponse_free(response);
if (response.reasonCode != MQTTCLIENT_SUCCESS) if (response.reasonCode != MQTTCLIENT_SUCCESS)
goto exit; goto exit;
...@@ -1227,6 +1238,7 @@ int test6a(struct Options options) ...@@ -1227,6 +1238,7 @@ int test6a(struct Options options)
opts2.cleansession = 1; opts2.cleansession = 1;
MyLog(LOGA_INFO, "Connecting Client_2 ..."); MyLog(LOGA_INFO, "Connecting Client_2 ...");
response = MQTTClient_connect5(test6_c2, &opts2, NULL, NULL); response = MQTTClient_connect5(test6_c2, &opts2, NULL, NULL);
MQTTResponse_free(response);
assert("Good rc from connect", response.reasonCode == MQTTCLIENT_SUCCESS, "rc was %d\n", response.reasonCode); 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); response = MQTTClient_subscribe5(test6_c2, test6_will_topic, 2, NULL, NULL);
......
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