Skip to content

Improve mosquitto client C++ wrapper to support more MQTT v5 features #3010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2.0.19 - 2023-11-xx
===================

Broker:
- Fix assert failure when loading a persistence file that contains
subscriptions with no client id.


2.0.18 - 2023-09-18
===================

Expand Down
1 change: 0 additions & 1 deletion client/rr_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause

#include "config.h"

#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
1 change: 0 additions & 1 deletion client/sub_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause

#include "config.h"

#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
1 change: 0 additions & 1 deletion client/sub_client_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
# include <io.h>
#endif

#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
8 changes: 6 additions & 2 deletions include/mosquitto.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ libmosq_EXPORT int mosquitto_username_pw_set(struct mosquitto *mosq, const char
* * mosq == NULL
* * host == NULL
* * port < 0
* * keepalive < 5
* * keepalive < 5 (keepalive == 0 is allowed, for an infinite keepalive)
* MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
* contains the error code, even on Windows.
* Use strerror_r() where available or FormatMessage() on
Expand Down Expand Up @@ -587,7 +587,7 @@ libmosq_EXPORT int mosquitto_connect_bind(struct mosquitto *mosq, const char *ho
* * mosq == NULL
* * host == NULL
* * port < 0
* * keepalive < 5
* * keepalive < 5 (keepalive == 0 is allowed, for an infinite keepalive)
* MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
* contains the error code, even on Windows.
* Use strerror_r() where available or FormatMessage() on
Expand Down Expand Up @@ -631,6 +631,8 @@ libmosq_EXPORT int mosquitto_connect_bind_v5(struct mosquitto *mosq, const char
*/
libmosq_EXPORT int mosquitto_connect_async(struct mosquitto *mosq, const char *host, int port, int keepalive);

libmosq_EXPORT int mosquitto_connect_async_v5(struct mosquitto *mosq, const char *host, int port, int keepalive, const mosquitto_property *properties);

/*
* Function: mosquitto_connect_bind_async
*
Expand Down Expand Up @@ -673,6 +675,8 @@ libmosq_EXPORT int mosquitto_connect_async(struct mosquitto *mosq, const char *h
*/
libmosq_EXPORT int mosquitto_connect_bind_async(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address);

libmosq_EXPORT int mosquitto_connect_bind_async_v5(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address, const mosquitto_property *properties);

/*
* Function: mosquitto_connect_srv
*
Expand Down
2 changes: 2 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ set_target_properties(libmosquitto PROPERTIES
OUTPUT_NAME mosquitto
VERSION ${VERSION}
SOVERSION 1
LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/linker.version
LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/linker.version"
)

install(TARGETS libmosquitto
Expand Down
30 changes: 30 additions & 0 deletions lib/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ int mosquitto_connect_async(struct mosquitto *mosq, const char *host, int port,
return mosquitto_connect_bind_async(mosq, host, port, keepalive, NULL);
}

int mosquitto_connect_async_v5(struct mosquitto *mosq, const char *host, int port, int keepalive, const mosquitto_property *properties)
{
return mosquitto_connect_bind_async_v5(mosq, host, port, keepalive, NULL, properties);
}

int mosquitto_connect_bind_async(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address)
{
Expand All @@ -142,6 +146,32 @@ int mosquitto_connect_bind_async(struct mosquitto *mosq, const char *host, int p
return mosquitto__reconnect(mosq, false);
}

int mosquitto_connect_bind_async_v5(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address, const mosquitto_property *properties)
{
int rc;

if(bind_address){
rc = mosquitto_string_option(mosq, MOSQ_OPT_BIND_ADDRESS, bind_address);
if(rc) return rc;
}

mosquitto_property_free_all(&mosq->connect_properties);
if(properties){
rc = mosquitto_property_check_all(CMD_CONNECT, properties);
if(rc) return rc;

rc = mosquitto_property_copy_all(&mosq->connect_properties, properties);
if(rc) return rc;
mosq->connect_properties->client_generated = true;
}

rc = mosquitto__connect_init(mosq, host, port, keepalive);
if(rc) return rc;

mosquitto__set_state(mosq, mosq_cs_new);

return mosquitto__reconnect(mosq, false);
}

int mosquitto_reconnect_async(struct mosquitto *mosq)
{
Expand Down
Loading