Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
icraggs committed May 24, 2021
2 parents 64a5ff3 + de1bc38 commit 47299d9
Show file tree
Hide file tree
Showing 27 changed files with 222 additions and 137 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ jobs:
- os: linux
compiler: gcc
dist: bionic
env: OPENSSL_ROOT_DIR= PAHO_BUILD_STATIC=TRUE PAHO_BUILD_SHARED=FALSE
env: OPENSSL_ROOT_DIR= PAHO_BUILD_STATIC=TRUE PAHO_BUILD_SHARED=FALSE PAHO_HIGH_PERFORMANCE=FALSE
- os: linux
compiler: gcc
dist: xenial
env: OPENSSL_ROOT_DIR= PAHO_BUILD_STATIC=TRUE PAHO_BUILD_SHARED=TRUE
env: OPENSSL_ROOT_DIR= PAHO_BUILD_STATIC=TRUE PAHO_BUILD_SHARED=TRUE PAHO_HIGH_PERFORMANCE=TRUE
- os: osx
compiler: clang
env: OPENSSL_ROOT_DIR=/usr/local/opt/openssl PAHO_BUILD_STATIC=FALSE PAHO_BUILD_SHARED=TRUE
env: OPENSSL_ROOT_DIR=/usr/local/opt/openssl PAHO_BUILD_STATIC=FALSE PAHO_BUILD_SHARED=TRUE PAHO_HIGH_PERFORMANC=FALSE
- os: linux
compiler: gcc
dist: trusty
env: OPENSSL_ROOT_DIR= PAHO_BUILD_STATIC=FALSE PAHO_BUILD_SHARED=TRUE
env: OPENSSL_ROOT_DIR= PAHO_BUILD_STATIC=FALSE PAHO_BUILD_SHARED=TRUE PAHO_HIGH_PERFORMANCE=FALSE
before_install:
#- if [ "$DEPLOY" = "true" ]; then ./travis-setup-deploy.sh; fi
- "./travis-install.sh"
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ ENDIF()

IF(PAHO_BUILD_DEB_PACKAGE)
set(CMAKE_INSTALL_DOCDIR share/doc/libpaho-mqtt)
set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON)
set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY ">=")
ENDIF()

ADD_SUBDIRECTORY(src)
Expand Down
5 changes: 4 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ environment:
OPENSSL_ROOT_DIR: "C:/OpenSSL-v111-Win64"
PAHO_BUILD_STATIC: FALSE
PAHO_BUILD_SHARED: TRUE
PAHO_HIGH_PERFORMANCE: FALSE
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
PAHO_WINDOWS_BUILD_BIT: x64
OPENSSL_ROOT_DIR: "C:/OpenSSL-Win64"
PAHO_BUILD_STATIC: TRUE
PAHO_BUILD_SHARED: FALSE
PAHO_HIGH_PERFORMANCE: TRUE
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
PAHO_WINDOWS_BUILD_BIT: x86
OPENSSL_ROOT_DIR: "C:/OpenSSL-Win32"
PAHO_BUILD_STATIC: FALSE
PAHO_BUILD_SHARED: TRUE
PAHO_HIGH_PERFORMANCE: TRUE

configuration: Debug
install:
Expand Down Expand Up @@ -45,7 +48,7 @@ build_script:
if "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2013" call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" %PAHO_WINDOWS_BUILD_BIT%
cmake -G "NMake Makefiles" -DPAHO_WITH_SSL=TRUE -DOPENSSL_ROOT_DIR=%OPENSSL_ROOT_DIR% -DPAHO_BUILD_DOCUMENTATION=FALSE -DPAHO_BUILD_SAMPLES=TRUE -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=TRUE -DPAHO_BUILD_STATIC=%PAHO_BUILD_STATIC% -DPAHO_BUILD_SHARED=%PAHO_BUILD_SHARED% ..
cmake -G "NMake Makefiles" -DPAHO_WITH_SSL=TRUE -DOPENSSL_ROOT_DIR=%OPENSSL_ROOT_DIR% -DPAHO_BUILD_DOCUMENTATION=FALSE -DPAHO_BUILD_SAMPLES=TRUE -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=TRUE -DPAHO_BUILD_STATIC=%PAHO_BUILD_STATIC% -DPAHO_BUILD_SHARED=%PAHO_BUILD_SHARED% -DPAHO_HIGH_PERFORMANCE=%PAHO_HIGH_PERFORMANCE% ..
nmake
Expand Down
6 changes: 3 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ELSEIF (UNIX)
# it or build will fail on uclibc or musl
FIND_LIBRARY(LIB_ANL anl)
IF(LIB_ANL)
SET(LIBS_SYSTEM "${LIBS_SYSTEM} ${LIB_ANL}")
SET(LIBS_SYSTEM "${LIBS_SYSTEM}" anl)
ENDIF()
ADD_DEFINITIONS(-D_GNU_SOURCE -fvisibility=hidden)
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Android")
Expand Down Expand Up @@ -306,15 +306,15 @@ ENDIF()
INSTALL(EXPORT eclipse-paho-mqtt-cTargets
FILE eclipse-paho-mqtt-cConfig.cmake
NAMESPACE eclipse-paho-mqtt-c::
DESTINATION lib/cmake/eclipse-paho-mqtt-c)
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/eclipse-paho-mqtt-c)

INCLUDE(CMakePackageConfigHelpers)
WRITE_BASIC_PACKAGE_VERSION_FILE("eclipse-paho-mqtt-cConfigVersion.cmake"
VERSION ${CLIENT_VERSION}
COMPATIBILITY SameMajorVersion)
INSTALL(FILES
"${CMAKE_CURRENT_BINARY_DIR}/eclipse-paho-mqtt-cConfigVersion.cmake"
DESTINATION lib/cmake/eclipse-paho-mqtt-c)
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/eclipse-paho-mqtt-c)

# Base64 test
ADD_EXECUTABLE( Base64Test EXCLUDE_FROM_ALL Base64.c Base64.h )
Expand Down
4 changes: 3 additions & 1 deletion src/Clients.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2020 IBM Corp.
* Copyright (c) 2009, 2021 IBM Corp. and Ian Craggs
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
Expand Down Expand Up @@ -125,7 +125,9 @@ typedef struct
unsigned int connected : 1; /**< whether it is currently connected */
unsigned int good : 1; /**< if we have an error on the socket we turn this off */
unsigned int ping_outstanding : 1;
unsigned int ping_due : 1; /**< we couldn't send a ping so we should send one when we can */
signed int connect_state : 4;
START_TIME_TYPE ping_due_time; /**< the time at which the ping should have been sent (ping_due) */
networkHandles net; /**< network info for this client */
int msgID; /**< the MQTT message id */
int keepAliveInterval; /**< the MQTT keep alive interval */
Expand Down
6 changes: 5 additions & 1 deletion src/Log.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@

trace_settings_type trace_settings =
{
#if defined(HIGH_PERFORMANCE)
LOG_ERROR,
#else
TRACE_MINIMUM,
#endif
400,
INVALID_LEVEL
};
Expand Down Expand Up @@ -227,7 +231,7 @@ void Log_setTraceCallback(Log_traceCallback* callback)

void Log_setTraceLevel(enum LOG_LEVELS level)
{
if (level < LOG_ERROR) /* the lowest we can go is LOG_ERROR */
if (level <= LOG_ERROR) /* the lowest we can go is LOG_ERROR */
trace_settings.trace_level = level;
trace_output_level = level;
}
Expand Down
4 changes: 3 additions & 1 deletion src/MQTTAsync.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2020 IBM Corp. and others
* Copyright (c) 2009, 2021 IBM Corp., Ian Craggs and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
Expand Down Expand Up @@ -1775,6 +1775,8 @@ const char* MQTTAsync_strerror(int code)
return "Client created for another version of MQTT";
case MQTTASYNC_0_LEN_WILL_TOPIC:
return "Zero length will topic on connect";
case MQTTASYNC_COMMAND_IGNORED:
return "Connect or disconnect command ignored";
}

chars = snprintf(buf, sizeof(buf), "Unknown error code %d", code);
Expand Down
50 changes: 27 additions & 23 deletions src/MQTTAsync.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2020 IBM Corp. and others
* Copyright (c) 2009, 2021 IBM Corp., Ian Craggs and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
Expand Down Expand Up @@ -29,7 +29,7 @@
* @cond MQTTAsync_main
* @mainpage Asynchronous MQTT client library for C
*
* &copy; Copyright IBM Corp. 2009, 2020 and others
* &copy; Copyright 2009, 2021 IBM Corp., Ian Craggs and others
*
* @brief An Asynchronous MQTT client library for C.
*
Expand Down Expand Up @@ -169,26 +169,30 @@
* Return code: Attempting SSL connection using non-SSL version of library
*/
#define MQTTASYNC_SSL_NOT_SUPPORTED -13
/**
* Return code: protocol prefix in serverURI should be tcp://, ssl://, ws:// or wss://
* The TLS enabled prefixes (ssl, wss) are only valid if the TLS version of the library
* is linked with.
*/
/**
* Return code: protocol prefix in serverURI should be tcp://, ssl://, ws:// or wss://
* The TLS enabled prefixes (ssl, wss) are only valid if the TLS version of the library
* is linked with.
*/
#define MQTTASYNC_BAD_PROTOCOL -14
/**
* Return code: don't use options for another version of MQTT
*/
#define MQTTASYNC_BAD_MQTT_OPTION -15
/**
* Return code: call not applicable to the client's version of MQTT
*/
#define MQTTASYNC_WRONG_MQTT_VERSION -16
/**
* Return code: 0 length will topic
*/
#define MQTTASYNC_0_LEN_WILL_TOPIC -17


/**
* Return code: don't use options for another version of MQTT
*/
#define MQTTASYNC_BAD_MQTT_OPTION -15
/**
* Return code: call not applicable to the client's version of MQTT
*/
#define MQTTASYNC_WRONG_MQTT_VERSION -16
/**
* Return code: 0 length will topic
*/
#define MQTTASYNC_0_LEN_WILL_TOPIC -17
/*
* Return code: connect or disconnect command ignored because there is already a connect or disconnect
* command at the head of the list waiting to be processed. Use the onSuccess/onFailure callbacks to wait
* for the previous connect or disconnect command to be complete.
*/
#define MQTTASYNC_COMMAND_IGNORED -18
/**
* Default MQTT version to connect with. Use 3.1.1 then fall back to 3.1
*/
Expand Down Expand Up @@ -550,7 +554,7 @@ typedef struct
int packet_type;
} MQTTAsync_failureData5;

#define MQTTAsync_failureData5_initializer {{'M', 'Q', 'F', 'D'}, 0, 0, MQTTREASONCODE_SUCCESS, MQTTProperties_initializer, 0, NULL}
#define MQTTAsync_failureData5_initializer {{'M', 'Q', 'F', 'D'}, 0, 0, MQTTREASONCODE_SUCCESS, MQTTProperties_initializer, 0, NULL, 0}

/** The data returned on completion of a successful API call in the response callback onSuccess. */
typedef struct
Expand Down Expand Up @@ -623,7 +627,7 @@ typedef struct
} alt;
} MQTTAsync_successData5;

#define MQTTAsync_successData5_initializer {{'M', 'Q', 'S', 'D'}, 0, 0, MQTTREASONCODE_SUCCESS, MQTTProperties_initializer}
#define MQTTAsync_successData5_initializer {{'M', 'Q', 'S', 'D'}, 0, 0, MQTTREASONCODE_SUCCESS, MQTTProperties_initializer, {.sub={0,0}}}

/**
* This is a callback function. The client application
Expand Down
61 changes: 48 additions & 13 deletions src/MQTTAsyncUtils.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2020 IBM Corp. and others
* Copyright (c) 2009, 2021 IBM Corp., Ian Craggs and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
Expand Down Expand Up @@ -757,8 +757,9 @@ static int MQTTAsync_unpersistInflightMessages(Clients* c)
}
#endif

#if 0
/**
* List callback function for comparing client handles and command types being CONNECT or DISCONNECT
* List callback function for comparing client handles and command types being CONNECT or DISCONNECT
* @param a first MQTTAsync_queuedCommand pointer
* @param b second MQTTAsync_queuedCommand pointer
* @return boolean indicating whether a and b are equal
Expand All @@ -778,33 +779,51 @@ static int clientCompareConnectCommand(void* a, void* b)
}
}
return 0; //Item NOT found in the list
}
}
#endif


int MQTTAsync_addCommand(MQTTAsync_queuedCommand* command, int command_size)
{
int rc = MQTTASYNC_SUCCESS;
int rc1 = 0;

FUNC_ENTRY;
MQTTAsync_lock_mutex(mqttcommand_mutex);
/* Don't set start time if the connect command is already in process #218 */
if ((command->command.type != CONNECT) || (command->client->c->connect_state == NOT_IN_PROGRESS))
command->command.start_time = MQTTTime_start_clock();

if (command->command.type == CONNECT ||
(command->command.type == DISCONNECT && command->command.details.dis.internal))
{
MQTTAsync_queuedCommand* head = NULL;
ListElement* current = MQTTAsync_commands->first;

if (MQTTAsync_commands->first)
head = (MQTTAsync_queuedCommand*)(MQTTAsync_commands->first->content);
/* Look for any connect or disconnect command belonging to this client. All the connects/disconnects
* are at the head of the list, so we don't search any further if we meet anything other than a
* connect or disconnect for any client.
*/
while (current)
{
MQTTAsync_queuedCommand* cur_cmd = (MQTTAsync_queuedCommand*)(current->content);
if (cur_cmd->command.type != CONNECT && cur_cmd->command.type != DISCONNECT)
break; /* end search if we meet anything other than connect or disconnect */
if (cur_cmd->client == command->client)
{
head = cur_cmd;
break;
}
current = current->prev;
}

if (head != NULL && head->client == command->client && head->command.type == command->command.type)
if (head)
{
MQTTAsync_freeCommand(command); /* ignore duplicate connect or disconnect command */
rc = MQTTASYNC_COMMAND_IGNORED;
}
else
{
ListRemoveItem(MQTTAsync_commands, command, clientCompareConnectCommand); /* remove command from the list if already there */
ListInsert(MQTTAsync_commands, command, command_size, MQTTAsync_commands->first); /* add to the head of the list */
}
}
else
{
Expand Down Expand Up @@ -884,11 +903,11 @@ int MQTTAsync_addCommand(MQTTAsync_queuedCommand* command, int command_size)
exit:
MQTTAsync_unlock_mutex(mqttcommand_mutex);
#if !defined(_WIN32) && !defined(_WIN64)
rc = Thread_signal_cond(send_cond);
if (rc != 0)
Log(LOG_ERROR, 0, "Error %d from signal cond", rc);
if ((rc1 = Thread_signal_cond(send_cond)) != 0)
Log(LOG_ERROR, 0, "Error %d from signal cond", rc1);
#else
rc = Thread_post_sem(send_sem);
if ((rc1 = Thread_post_sem(send_sem)) != 0)
Log(LOG_ERROR, 0, "Error %d from signal cond", rc1);
#endif
FUNC_EXIT_RC(rc);
return rc;
Expand Down Expand Up @@ -1370,6 +1389,9 @@ static int MQTTAsync_processCommand(void)
goto exit;
}

/* Initialize the mask */
memset(p->mask, 0, sizeof(p->mask));

p->payload = command->command.details.pub.payload;
p->payloadlen = command->command.details.pub.payloadlen;
p->topic = command->command.details.pub.destinationName;
Expand Down Expand Up @@ -2309,6 +2331,7 @@ static void MQTTAsync_closeOnly(Clients* client, enum MQTTReasonCodes reasonCode
FUNC_ENTRY;
client->good = 0;
client->ping_outstanding = 0;
client->ping_due = 0;
if (client->net.socket > 0)
{
MQTTProtocol_checkPendingWrites();
Expand Down Expand Up @@ -2650,6 +2673,18 @@ static int MQTTAsync_connecting(MQTTAsyncs* m)
#endif

FUNC_ENTRY;

/* This was reported in #1007, but I've not been able to reproduce it. It feels like this is
* covering up the issue, if it exists. If the error message is ever seen, please consider
* reporting the circumstances so that more debugging can occur. Thanks - IGC.
*/
if (m->connect.details.conn.MQTTVersion == MQTTVERSION_DEFAULT) /* should not happen - #1007 */
{
Log(LOG_ERROR, -1, "MQTT version is 0 in MQTTAsync_connecting");
m->connect.details.conn.MQTTVersion = (m->c->MQTTVersion == MQTTVERSION_DEFAULT) ? MQTTVERSION_3_1_1 : m->c->MQTTVersion;
}
/* End of #1007 avoiding code */

if (m->serverURIcount > 0)
{
serverURI = m->serverURIs[m->connect.details.conn.currentURI];
Expand Down
6 changes: 3 additions & 3 deletions src/MQTTClient.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2020 IBM Corp. and others
* Copyright (c) 2009, 2021 IBM Corp., Ian Craggs and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
Expand Down Expand Up @@ -968,7 +968,6 @@ static thread_return_type WINAPI MQTTClient_run(void* n)
}
}
#endif

else if (m->c->connect_state == WEBSOCKET_IN_PROGRESS)
{
if (rc != TCPSOCKET_INTERRUPTED)
Expand Down Expand Up @@ -1065,6 +1064,7 @@ static void MQTTClient_closeSession(Clients* client, enum MQTTReasonCodes reason
FUNC_ENTRY;
client->good = 0;
client->ping_outstanding = 0;
client->ping_due = 0;
if (client->net.socket > 0)
{
if (client->connected)
Expand Down Expand Up @@ -2647,7 +2647,7 @@ static MQTTPacket* MQTTClient_waitfor(MQTTClient handle, int packet_type, int* r
}
}
#endif
else if (m->c->connect_state == WEBSOCKET_IN_PROGRESS )
else if (m->c->connect_state == WEBSOCKET_IN_PROGRESS && *rc != TCPSOCKET_INTERRUPTED)
{
*rc = 1;
break;
Expand Down
Loading

0 comments on commit 47299d9

Please sign in to comment.