Commit ede005c4 authored by Ian Craggs's avatar Ian Craggs

Async client specific test for client topic aliases

parent 372ef9e8
...@@ -96,7 +96,7 @@ SYNC_TESTS = ${addprefix ${blddir}/test/,${TEST_FILES_C}} ...@@ -96,7 +96,7 @@ SYNC_TESTS = ${addprefix ${blddir}/test/,${TEST_FILES_C}}
TEST_FILES_CS = test3 TEST_FILES_CS = test3
SYNC_SSL_TESTS = ${addprefix ${blddir}/test/,${TEST_FILES_CS}} SYNC_SSL_TESTS = ${addprefix ${blddir}/test/,${TEST_FILES_CS}}
TEST_FILES_A = test4 test45 test6 test9 test_mqtt4async TEST_FILES_A = test4 test45 test6 test9 test_mqtt4async test11
ASYNC_TESTS = ${addprefix ${blddir}/test/,${TEST_FILES_A}} ASYNC_TESTS = ${addprefix ${blddir}/test/,${TEST_FILES_A}}
TEST_FILES_AS = test5 TEST_FILES_AS = test5
......
...@@ -322,6 +322,9 @@ typedef struct MQTTAsync_struct ...@@ -322,6 +322,9 @@ typedef struct MQTTAsync_struct
MQTTAsync_connected* connected; MQTTAsync_connected* connected;
void* connected_context; /* the context to be associated with the connected callback*/ void* connected_context; /* the context to be associated with the connected callback*/
MQTTAsync_disconnected* disconnected;
void* disconnected_context; /* the context to be associated with the disconnected callback*/
/* Each time connect is called, we store the options that were used. These are reused in /* Each time connect is called, we store the options that were used. These are reused in
any call to reconnect, or an automatic reconnect attempt */ any call to reconnect, or an automatic reconnect attempt */
MQTTAsync_command connect; /* Connect operation properties */ MQTTAsync_command connect; /* Connect operation properties */
...@@ -2255,6 +2258,17 @@ static thread_return_type WINAPI MQTTAsync_receiveThread(void* n) ...@@ -2255,6 +2258,17 @@ static thread_return_type WINAPI MQTTAsync_receiveThread(void* n)
} }
rc = MQTTProtocol_handleUnsubacks(pack, m->c->net.socket); rc = MQTTProtocol_handleUnsubacks(pack, m->c->net.socket);
} }
else if (pack->header.bits.type == DISCONNECT)
{
Ack* disc = (Ack*)pack;
if (m->disconnected)
{
Log(TRACE_MIN, -1, "Calling disconnected for client %s", m->c->clientID);
(*(m->disconnected))(m->disconnected_context, &disc->properties, disc->rc);
}
MQTTPacket_freeAck(disc);
}
} }
} }
} }
...@@ -2341,6 +2355,28 @@ int MQTTAsync_setCallbacks(MQTTAsync handle, void* context, ...@@ -2341,6 +2355,28 @@ int MQTTAsync_setCallbacks(MQTTAsync handle, void* context,
} }
int MQTTAsync_setDisconnected(MQTTAsync handle, void* context, MQTTAsync_disconnected* disconnected)
{
int rc = MQTTASYNC_SUCCESS;
MQTTAsyncs* m = handle;
FUNC_ENTRY;
MQTTAsync_lock_mutex(mqttasync_mutex);
if (m == NULL || m->c->connect_state != NOT_IN_PROGRESS)
rc = MQTTASYNC_FAILURE;
else
{
m->disconnected_context = context;
m->disconnected = disconnected;
}
MQTTAsync_unlock_mutex(mqttasync_mutex);
FUNC_EXIT_RC(rc);
return rc;
}
int MQTTAsync_setConnected(MQTTAsync handle, void* context, MQTTAsync_connected* connected) int MQTTAsync_setConnected(MQTTAsync handle, void* context, MQTTAsync_connected* connected)
{ {
int rc = MQTTASYNC_SUCCESS; int rc = MQTTASYNC_SUCCESS;
...@@ -3212,6 +3248,7 @@ int MQTTAsync_sendMessage(MQTTAsync handle, const char* destinationName, const M ...@@ -3212,6 +3248,7 @@ int MQTTAsync_sendMessage(MQTTAsync handle, const char* destinationName, const M
MQTTAsync_responseOptions* response) MQTTAsync_responseOptions* response)
{ {
int rc = MQTTASYNC_SUCCESS; int rc = MQTTASYNC_SUCCESS;
MQTTAsyncs* m = handle;
FUNC_ENTRY; FUNC_ENTRY;
if (message == NULL) if (message == NULL)
...@@ -3226,6 +3263,9 @@ int MQTTAsync_sendMessage(MQTTAsync handle, const char* destinationName, const M ...@@ -3226,6 +3263,9 @@ int MQTTAsync_sendMessage(MQTTAsync handle, const char* destinationName, const M
goto exit; goto exit;
} }
if (m->c->MQTTVersion >= MQTTVERSION_5)
response->properties = message->properties;
rc = MQTTAsync_send(handle, destinationName, message->payloadlen, message->payload, rc = MQTTAsync_send(handle, destinationName, message->payloadlen, message->payload,
message->qos, message->retained, response); message->qos, message->retained, response);
exit: exit:
......
...@@ -394,6 +394,32 @@ typedef void MQTTAsync_connectionLost(void* context, char* cause); ...@@ -394,6 +394,32 @@ typedef void MQTTAsync_connectionLost(void* context, char* cause);
*/ */
typedef void MQTTAsync_connected(void* context, char* cause); typedef void MQTTAsync_connected(void* context, char* cause);
/**
* This is a callback function, which will be called when the client
* library receives a disconnect packet.
* @param context A pointer to the <i>context</i> value originally passed to
* MQTTAsync_setCallbacks(), which contains any application-specific context.
* @param properties the properties in the disconnect packet.
* @param properties the reason code from the disconnect packet
* Currently, <i>cause</i> is always set to NULL.
*/
typedef void MQTTAsync_disconnected(void* context, MQTTProperties* properties,
enum MQTTReasonCodes reasonCode);
/**
* Sets the MQTTAsync_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 MQTTAsync_setDisconnected(MQTTAsync handle, void* context, MQTTAsync_disconnected* co);
/** The data returned on completion of an unsuccessful API call in the response callback onFailure. */ /** The data returned on completion of an unsuccessful API call in the response callback onFailure. */
typedef struct typedef struct
......
...@@ -570,6 +570,20 @@ void MQTTPacket_freePublish(Publish* pack) ...@@ -570,6 +570,20 @@ void MQTTPacket_freePublish(Publish* pack)
} }
/**
* Free allocated storage for an ack packet.
* @param pack pointer to the publish packet structure
*/
void MQTTPacket_freeAck(Ack* pack)
{
FUNC_ENTRY;
if (pack->MQTTVersion >= MQTTVERSION_5)
MQTTProperties_free(&pack->properties);
free(pack);
FUNC_EXIT;
}
/** /**
* Send an MQTT acknowledgement packet down a socket. * Send an MQTT acknowledgement packet down a socket.
* @param type the MQTT packet type e.g. SUBACK * @param type the MQTT packet type e.g. SUBACK
......
...@@ -249,6 +249,7 @@ int MQTTPacket_send_publish(Publish* pack, int dup, int qos, int retained, netwo ...@@ -249,6 +249,7 @@ int MQTTPacket_send_publish(Publish* pack, int dup, int qos, int retained, netwo
int MQTTPacket_send_puback(int msgid, networkHandles* net, const char* clientID); int MQTTPacket_send_puback(int msgid, networkHandles* net, const char* clientID);
void* MQTTPacket_ack(int MQTTVersion, unsigned char aHeader, char* data, size_t datalen); void* MQTTPacket_ack(int MQTTVersion, unsigned char aHeader, char* data, size_t datalen);
void MQTTPacket_freeAck(Ack* pack);
void MQTTPacket_freeSuback(Suback* pack); void MQTTPacket_freeSuback(Suback* pack);
void MQTTPacket_freeUnsuback(Unsuback* pack); void MQTTPacket_freeUnsuback(Unsuback* pack);
int MQTTPacket_send_pubrec(int msgid, networkHandles* net, const char* clientID); int MQTTPacket_send_pubrec(int msgid, networkHandles* net, const char* clientID);
......
...@@ -584,6 +584,26 @@ SET_TESTS_PROPERTIES( ...@@ -584,6 +584,26 @@ SET_TESTS_PROPERTIES(
PROPERTIES TIMEOUT 540 PROPERTIES TIMEOUT 540
) )
ADD_EXECUTABLE(
test11
test11.c
)
TARGET_LINK_LIBRARIES(
test11
paho-mqtt3a
)
ADD_TEST(
NAME test11-1-client_topic_aliases
COMMAND "test11" "--test_no" "1" "--connection" ${MQTT_TEST_BROKER} "--proxy_connection" ${MQTT_TEST_PROXY}
)
SET_TESTS_PROPERTIES(
test11-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.
...@@ -55,7 +55,7 @@ struct Options ...@@ -55,7 +55,7 @@ struct Options
int iterations; int iterations;
} options = } options =
{ {
"iot.eclipse.org:1883", "localhost:1883",
0, 0,
-1, -1,
10000, 10000,
...@@ -128,14 +128,18 @@ void MyLog(int LOGA_level, char* format, ...) ...@@ -128,14 +128,18 @@ void MyLog(int LOGA_level, char* format, ...)
va_list args; va_list args;
struct timeb ts; struct timeb ts;
struct tm *timeinfo; struct tm timeinfo;
if (LOGA_level == LOGA_DEBUG && options.verbose == 0) if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
return; return;
ftime(&ts); ftime(&ts);
timeinfo = localtime(&ts.time); #if defined(WIN32) || defined(_WINDOWS)
strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo); localtime_s(&timeinfo, &ts.time);
#else
localtime_r(&ts.time, &timeinfo);
#endif
strftime(msg_buf, 80, "%Y%m%d %H%M%S", &timeinfo);
sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm); sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
...@@ -357,7 +361,7 @@ int test1_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync ...@@ -357,7 +361,7 @@ int test1_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync
property.value.value.data = "test user property value"; property.value.value.data = "test user property value";
property.value.value.len = strlen(property.value.value.data); property.value.value.len = strlen(property.value.value.data);
MQTTProperties_add(&props, &property); MQTTProperties_add(&props, &property);
opts.properties = props; pubmsg.properties = props;
pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11"; pubmsg.payload = "a much longer message that we can shorten to the extent that we need to payload up to 11";
pubmsg.payloadlen = 11; pubmsg.payloadlen = 11;
......
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