Commit 72d05f95 authored by Al S-M's avatar Al S-M

Merge branch '415667'

parents fd74d051 dc4318f7
......@@ -83,11 +83,11 @@ extern mutex_type stack_mutex;
extern mutex_type heap_mutex;
extern mutex_type log_mutex;
BOOL APIENTRY DllMain(HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved)
DWORD ul_reason_for_call,
LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
Log(TRACE_MAX, -1, "DLL process attach");
if (mqttasync_mutex == NULL)
......@@ -104,8 +104,8 @@ BOOL APIENTRY DllMain(HANDLE hModule,
Log(TRACE_MAX, -1, "DLL thread detach");
case DLL_PROCESS_DETACH:
Log(TRACE_MAX, -1, "DLL process detach");
}
return TRUE;
}
return TRUE;
}
#else
static pthread_mutex_t mqttasync_mutex_store = PTHREAD_MUTEX_INITIALIZER;
......@@ -1486,11 +1486,11 @@ thread_return_type WINAPI MQTTAsync_receiveThread(void* n)
m->connect.details.conn.serverURIs[m->connect.details.conn.currentURI]);
MQTTAsync_addCommand(conn, sizeof(m->connect));
}
else
{
MQTTAsync_closeSession(m->c);
MQTTAsync_freeConnect(m->connect);
if (m->connect.onFailure)
else
{
MQTTAsync_closeSession(m->c);
MQTTAsync_freeConnect(m->connect);
if (m->connect.onFailure)
{
MQTTAsync_failureData data;
......@@ -1520,24 +1520,24 @@ thread_return_type WINAPI MQTTAsync_receiveThread(void* n)
Log(LOG_ERROR, -1, "Subscribe command not removed from command list");
if (command->command.onSuccess)
{
MQTTAsync_successData data;
Suback* sub = (Suback*)pack;
int* array = NULL;
if (sub->qoss->count == 1)
data.alt.qos = *(int*)(sub->qoss->first->content);
else if (sub->qoss->count > 1)
{
ListElement* cur_qos = NULL;
int* element = array = data.alt.qosList = malloc(sub->qoss->count * sizeof(int));
while (ListNextElement(sub->qoss, &cur_qos))
*element++ = *(int*)(cur_qos->content);
}
data.token = command->command.token;
rc = MQTTProtocol_handleSubacks(pack, m->c->net.socket);
MQTTAsync_successData data;
Suback* sub = (Suback*)pack;
int* array = NULL;
if (sub->qoss->count == 1)
data.alt.qos = *(int*)(sub->qoss->first->content);
else if (sub->qoss->count > 1)
{
ListElement* cur_qos = NULL;
int* element = array = data.alt.qosList = malloc(sub->qoss->count * sizeof(int));
while (ListNextElement(sub->qoss, &cur_qos))
*element++ = *(int*)(cur_qos->content);
}
data.token = command->command.token;
rc = MQTTProtocol_handleSubacks(pack, m->c->net.socket);
handleCalled = 1;
Log(TRACE_MIN, -1, "Calling subscribe success for client %s", m->c->clientID);
Log(TRACE_MIN, -1, "Calling subscribe success for client %s", m->c->clientID);
Thread_unlock_mutex(mqttasync_mutex);
(*(command->command.onSuccess))(command->command.context, &data);
Thread_lock_mutex(mqttasync_mutex);
......@@ -2045,15 +2045,15 @@ int MQTTAsync_connect(MQTTAsync handle, MQTTAsync_connectOptions* options)
m->c->cleansession = options->cleansession;
m->c->maxInflightMessages = options->maxInflight;
if (m->c->will)
{
free(m->c->will);
if (m->c->will)
{
free(m->c->will);
m->c->will = NULL;
}
}
if (options->will && options->will->struct_version == 0)
{
m->c->will = malloc(sizeof(willMessages));
m->c->will = malloc(sizeof(willMessages));
m->c->will->msg = malloc(strlen(options->will->message) + 1);
strcpy(m->c->will->msg, options->will->message);
m->c->will->qos = options->will->qos;
......@@ -2448,8 +2448,17 @@ int MQTTAsync_connecting(MQTTAsyncs* m)
rc = SOCKET_ERROR;
goto exit;
}
else if (rc == 1 && !m->c->cleansession && m->c->session == NULL)
m->c->session = SSL_get1_session(m->c->net.ssl);
else if (rc == 1) {
rc = MQTTCLIENT_SUCCESS;
m->c->connect_state = 3;
if (MQTTPacket_send_connect(m->c) == SOCKET_ERROR)
{
rc = SOCKET_ERROR;
goto exit;
}
if(!m->c->cleansession && m->c->session == NULL)
m->c->session = SSL_get1_session(m->c->net.ssl);
}
}
else
{
......@@ -2473,6 +2482,8 @@ int MQTTAsync_connecting(MQTTAsyncs* m)
if ((rc = SSLSocket_connect(m->c->net.ssl, m->c->net.socket)) != 1)
goto exit;
if(!m->c->cleansession && m->c->session == NULL)
m->c->session = SSL_get1_session(m->c->net.ssl);
m->c->connect_state = 3; /* SSL connect completed, in which case send the MQTT connect packet */
if ((rc = MQTTPacket_send_connect(m->c)) == SOCKET_ERROR)
goto exit;
......
......@@ -70,11 +70,11 @@ extern mutex_type stack_mutex;
extern mutex_type heap_mutex;
extern mutex_type log_mutex;
BOOL APIENTRY DllMain(HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved)
DWORD ul_reason_for_call,
LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
Log(TRACE_MAX, -1, "DLL process attach");
if (mqttclient_mutex == NULL)
......@@ -90,8 +90,8 @@ BOOL APIENTRY DllMain(HANDLE hModule,
Log(TRACE_MAX, -1, "DLL thread detach");
case DLL_PROCESS_DETACH:
Log(TRACE_MAX, -1, "DLL process detach");
}
return TRUE;
}
return TRUE;
}
#else
static pthread_mutex_t mqttclient_mutex_store = PTHREAD_MUTEX_INITIALIZER;
......@@ -737,7 +737,7 @@ int MQTTClient_connectURI(MQTTClient handle, MQTTClient_connectOptions* options,
if (options->will && options->will->struct_version == 0)
{
m->c->will = malloc(sizeof(willMessages));
m->c->will = malloc(sizeof(willMessages));
m->c->will->msg = options->will->message;
m->c->will->qos = options->will->qos;
m->c->will->retained = options->will->retained;
......@@ -795,8 +795,17 @@ int MQTTClient_connectURI(MQTTClient handle, MQTTClient_connectOptions* options,
rc = SOCKET_ERROR;
goto exit;
}
else if (rc == 1 && !m->c->cleansession && m->c->session == NULL)
m->c->session = SSL_get1_session(m->c->net.ssl);
else if (rc == 1) {
rc = MQTTCLIENT_SUCCESS;
m->c->connect_state = 3;
if (MQTTPacket_send_connect(m->c) == SOCKET_ERROR)
{
rc = SOCKET_ERROR;
goto exit;
}
if(!m->c->cleansession && m->c->session == NULL)
m->c->session = SSL_get1_session(m->c->net.ssl);
}
}
else
{
......@@ -829,6 +838,8 @@ int MQTTClient_connectURI(MQTTClient handle, MQTTClient_connectOptions* options,
rc = SOCKET_ERROR;
goto exit;
}
if(!m->c->cleansession && m->c->session == NULL)
m->c->session = SSL_get1_session(m->c->net.ssl);
m->c->connect_state = 3; /* TCP connect completed, in which case send the MQTT connect packet */
if (MQTTPacket_send_connect(m->c) == SOCKET_ERROR)
{
......@@ -962,11 +973,11 @@ int MQTTClient_connect(MQTTClient handle, MQTTClient_connectOptions* options)
}
exit:
if (m->c->will)
{
if (m->c->will)
{
free(m->c->will);
m->c->will = NULL;
}
}
Thread_unlock_mutex(mqttclient_mutex);
FUNC_EXIT_RC(rc);
return rc;
......
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