From 5487395fb67ad2e2b6dac1ff67bd0ac289383f09 Mon Sep 17 00:00:00 2001 From: David Audet Date: Wed, 21 Sep 2016 13:35:05 -0700 Subject: [PATCH 01/37] Adding Dockerfiles to build versioned Docker images (#226) * Adding Dockerfiles to build versioned Docker images Dockerfiles have been added to create Docker images for Mosquitto v1.4.4 and v1.4.8 using Alpine Linux as a base. Different directories have been added for each version to decouple the configuration and entrypoint scripts. Currently they contain the same content, but this could change in the future. Docker Hub will also need to pull from specific directories when official docker images will be built and hosted on Docker Hub. * Removing unnecessary default config and volumes Mount points are created in the image, but volumes are not automatically created. The user can still create volumes for these mount points, but is not required to. The default configuration file is now copied from /etc/mosquitto/mosquitto.conf to /mosquitto/config/mosquitto.conf. The user can override this file by mounting a local configuration file to /mosquitto/config. Signed-off-by: David Audet --- docker/1.4.4/Dockerfile | 13 ++++++++ docker/1.4.4/README.md | 49 +++++++++++++++++++++++++++++++ docker/1.4.4/docker-entrypoint.sh | 5 ++++ docker/1.4.8/Dockerfile | 13 ++++++++ docker/1.4.8/README.md | 49 +++++++++++++++++++++++++++++++ docker/1.4.8/docker-entrypoint.sh | 5 ++++ docker/README.md | 4 +++ 7 files changed, 138 insertions(+) create mode 100644 docker/1.4.4/Dockerfile create mode 100644 docker/1.4.4/README.md create mode 100755 docker/1.4.4/docker-entrypoint.sh create mode 100644 docker/1.4.8/Dockerfile create mode 100644 docker/1.4.8/README.md create mode 100755 docker/1.4.8/docker-entrypoint.sh create mode 100644 docker/README.md diff --git a/docker/1.4.4/Dockerfile b/docker/1.4.4/Dockerfile new file mode 100644 index 00000000..b568aeda --- /dev/null +++ b/docker/1.4.4/Dockerfile @@ -0,0 +1,13 @@ +FROM alpine:3.3 +MAINTAINER David Audet + +LABEL Description="Eclipse Mosquitto MQTT Broker" + +RUN apk --no-cache --update add mosquitto=1.4.4-r0 && \ + mkdir -p /mosquitto/config /mosquitto/data /mosquitto/log && \ + cp /etc/mosquitto/mosquitto.conf /mosquitto/config && \ + chown -R mosquitto:mosquitto /mosquitto + +COPY docker-entrypoint.sh / +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["/usr/sbin/mosquitto", "-c", "/mosquitto/config/mosquitto.conf"] diff --git a/docker/1.4.4/README.md b/docker/1.4.4/README.md new file mode 100644 index 00000000..795dd2b1 --- /dev/null +++ b/docker/1.4.4/README.md @@ -0,0 +1,49 @@ +#Eclipse Mosquitto v1.4.4 Docker Image + +##Mount Points + +Three mount points have been created in the image to be used for configuration, persistent storage and logs. +``` +/mosquitto/config +/mosquitto/data +/mosquitto/log +``` + + +##Configuration + +When running the image, the default configuration values are used. +To use a custom configuration file, mount a **local** configuration file to `/mosquitto/conf/mosquitto.conf` +``` +docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf mosquitto:1.4.4 +``` + +Configuration can be changed to: + +* persist data to `/mosquitto/data` +* log to `/mosquitto/log/mosquitto.log` + +i.e. add the following to `mosquitto.conf`: +``` +persistence true +persistence_location /mosquitto/data/ + +log_dest file /mosquitto/log/mosquitto.log +``` + +**Note**: If a volume is used, the data will persist between containers. + +##Build +Build the image: +``` +docker build -t mosquitto:1.4.4 . +``` + +##Run +Run a container using the new image: +``` +docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.4 +``` +:boom: if the mosquitto configuration (mosquitto.conf) was modified +to use non-default ports, the docker run command will need to be updated +to expose the ports that have been configured. \ No newline at end of file diff --git a/docker/1.4.4/docker-entrypoint.sh b/docker/1.4.4/docker-entrypoint.sh new file mode 100755 index 00000000..1a9fc8d0 --- /dev/null +++ b/docker/1.4.4/docker-entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/ash + +set -e +exec "$@" + diff --git a/docker/1.4.8/Dockerfile b/docker/1.4.8/Dockerfile new file mode 100644 index 00000000..b005b530 --- /dev/null +++ b/docker/1.4.8/Dockerfile @@ -0,0 +1,13 @@ +FROM alpine:3.4 +MAINTAINER David Audet + +LABEL Description="Eclipse Mosquitto MQTT Broker" + +RUN apk --no-cache --update add mosquitto=1.4.8-r2 && \ + mkdir -p /mosquitto/config /mosquitto/data /mosquitto/log && \ + cp /etc/mosquitto/mosquitto.conf /mosquitto/config && \ + chown -R mosquitto:mosquitto /mosquitto + +COPY docker-entrypoint.sh / +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["/usr/sbin/mosquitto", "-c", "/mosquitto/config/mosquitto.conf"] diff --git a/docker/1.4.8/README.md b/docker/1.4.8/README.md new file mode 100644 index 00000000..fd8ae40a --- /dev/null +++ b/docker/1.4.8/README.md @@ -0,0 +1,49 @@ +#Eclipse Mosquitto v1.4.8 Docker Image + +##Mount Points + +Three mount points have been created in the image to be used for configuration, persistent storage and logs. +``` +/mosquitto/config +/mosquitto/data +/mosquitto/log +``` + + +##Configuration + +When running the image, the default configuration values are used. +To use a custom configuration file, mount a **local** configuration file to `/mosquitto/conf/mosquitto.conf` +``` +docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf mosquitto:1.4.8 +``` + +Configuration can be changed to: + +* persist data to `/mosquitto/data` +* log to `/mosquitto/log/mosquitto.log` + +i.e. add the following to `mosquitto.conf`: +``` +persistence true +persistence_location /mosquitto/data/ + +log_dest file /mosquitto/log/mosquitto.log +``` + +**Note**: If a volume is used, the data will persist between containers. + +##Build +Build the image: +``` +docker build -t mosquitto:1.4.8 . +``` + +##Run +Run a container using the new image: +``` +docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.8 +``` +:boom: if the mosquitto configuration (mosquitto.conf) was modified +to use non-default ports, the docker run command will need to be updated +to expose the ports that have been configured. diff --git a/docker/1.4.8/docker-entrypoint.sh b/docker/1.4.8/docker-entrypoint.sh new file mode 100755 index 00000000..1a9fc8d0 --- /dev/null +++ b/docker/1.4.8/docker-entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/ash + +set -e +exec "$@" + diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 00000000..6fe5506c --- /dev/null +++ b/docker/README.md @@ -0,0 +1,4 @@ +# Docker Images + +This directory contains the required files to build Mosquitto Docker images. + From 51bfdc9ed48ec3317280fe17d8b2b7dc66a1c349 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 5 Oct 2016 15:52:09 +0100 Subject: [PATCH 02/37] Improve logo files. Make mosquitto-logo-only.svg square. Add mosquitto-logo-min.svg which is more suitable for very small images. --- logo/mosquitto-logo-min.svg | 65 ++++++++++++++++++++++++++++++++++++ logo/mosquitto-logo-only.svg | 34 ++++++++++--------- 2 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 logo/mosquitto-logo-min.svg diff --git a/logo/mosquitto-logo-min.svg b/logo/mosquitto-logo-min.svg new file mode 100644 index 00000000..5438312b --- /dev/null +++ b/logo/mosquitto-logo-min.svg @@ -0,0 +1,65 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/logo/mosquitto-logo-only.svg b/logo/mosquitto-logo-only.svg index 90304382..e43167d7 100644 --- a/logo/mosquitto-logo-only.svg +++ b/logo/mosquitto-logo-only.svg @@ -14,8 +14,8 @@ inkscape:version="0.91 r13725" xml:space="preserve" width="278.23288" - height="212.13112" - viewBox="0 0 278.23288 212.13112" + height="278.23288" + viewBox="0 0 278.23288 278.23288" sodipodi:docname="mosquitto-logo-only.svg">image/svg+xml \ No newline at end of file + transform="matrix(1.25,0,0,-1.25,-387.06488,575.71439)"> \ No newline at end of file From 25a1f7d1994fd4b8d1d25ab0275f7a8f071abfb1 Mon Sep 17 00:00:00 2001 From: David Audet Date: Tue, 20 Dec 2016 13:48:19 -0800 Subject: [PATCH 03/37] Update Dockerfiles to not save the apk cache When installing the Mosquitto package from Alpine Linux, we don't need to save the latest package index to the cache. We are specifically requesting the latest package index each time we install Mosquitto and not using the local cache at all (--no-cache). Signed-off-by: David Audet --- docker/1.4.4/Dockerfile | 2 +- docker/1.4.8/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/1.4.4/Dockerfile b/docker/1.4.4/Dockerfile index b568aeda..bd757e3b 100644 --- a/docker/1.4.4/Dockerfile +++ b/docker/1.4.4/Dockerfile @@ -3,7 +3,7 @@ MAINTAINER David Audet LABEL Description="Eclipse Mosquitto MQTT Broker" -RUN apk --no-cache --update add mosquitto=1.4.4-r0 && \ +RUN apk --no-cache add mosquitto=1.4.4-r0 && \ mkdir -p /mosquitto/config /mosquitto/data /mosquitto/log && \ cp /etc/mosquitto/mosquitto.conf /mosquitto/config && \ chown -R mosquitto:mosquitto /mosquitto diff --git a/docker/1.4.8/Dockerfile b/docker/1.4.8/Dockerfile index b005b530..a9027a78 100644 --- a/docker/1.4.8/Dockerfile +++ b/docker/1.4.8/Dockerfile @@ -3,7 +3,7 @@ MAINTAINER David Audet LABEL Description="Eclipse Mosquitto MQTT Broker" -RUN apk --no-cache --update add mosquitto=1.4.8-r2 && \ +RUN apk --no-cache add mosquitto=1.4.8-r2 && \ mkdir -p /mosquitto/config /mosquitto/data /mosquitto/log && \ cp /etc/mosquitto/mosquitto.conf /mosquitto/config && \ chown -R mosquitto:mosquitto /mosquitto From 37cbadc3116d2a0645f4924a617165901c5dc10b Mon Sep 17 00:00:00 2001 From: Adam Giemza Date: Thu, 5 Jan 2017 22:23:58 +0100 Subject: [PATCH 04/37] added docker support for version 1.4.10-r2 based on alpine 3.5 (#346) Signed-off-by: Adam Giemza --- docker/1.4.10/Dockerfile | 13 ++++++++ docker/1.4.10/README.md | 49 ++++++++++++++++++++++++++++++ docker/1.4.10/docker-entrypoint.sh | 5 +++ 3 files changed, 67 insertions(+) create mode 100644 docker/1.4.10/Dockerfile create mode 100644 docker/1.4.10/README.md create mode 100755 docker/1.4.10/docker-entrypoint.sh diff --git a/docker/1.4.10/Dockerfile b/docker/1.4.10/Dockerfile new file mode 100644 index 00000000..ee55de18 --- /dev/null +++ b/docker/1.4.10/Dockerfile @@ -0,0 +1,13 @@ +FROM alpine:3.5 +MAINTAINER David Audet + +LABEL Description="Eclipse Mosquitto MQTT Broker" + +RUN apk --no-cache --update add mosquitto=1.4.10-r2 && \ + mkdir -p /mosquitto/config /mosquitto/data /mosquitto/log && \ + cp /etc/mosquitto/mosquitto.conf /mosquitto/config && \ + chown -R mosquitto:mosquitto /mosquitto + +COPY docker-entrypoint.sh / +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["/usr/sbin/mosquitto", "-c", "/mosquitto/config/mosquitto.conf"] diff --git a/docker/1.4.10/README.md b/docker/1.4.10/README.md new file mode 100644 index 00000000..fd8ae40a --- /dev/null +++ b/docker/1.4.10/README.md @@ -0,0 +1,49 @@ +#Eclipse Mosquitto v1.4.8 Docker Image + +##Mount Points + +Three mount points have been created in the image to be used for configuration, persistent storage and logs. +``` +/mosquitto/config +/mosquitto/data +/mosquitto/log +``` + + +##Configuration + +When running the image, the default configuration values are used. +To use a custom configuration file, mount a **local** configuration file to `/mosquitto/conf/mosquitto.conf` +``` +docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf mosquitto:1.4.8 +``` + +Configuration can be changed to: + +* persist data to `/mosquitto/data` +* log to `/mosquitto/log/mosquitto.log` + +i.e. add the following to `mosquitto.conf`: +``` +persistence true +persistence_location /mosquitto/data/ + +log_dest file /mosquitto/log/mosquitto.log +``` + +**Note**: If a volume is used, the data will persist between containers. + +##Build +Build the image: +``` +docker build -t mosquitto:1.4.8 . +``` + +##Run +Run a container using the new image: +``` +docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.8 +``` +:boom: if the mosquitto configuration (mosquitto.conf) was modified +to use non-default ports, the docker run command will need to be updated +to expose the ports that have been configured. diff --git a/docker/1.4.10/docker-entrypoint.sh b/docker/1.4.10/docker-entrypoint.sh new file mode 100755 index 00000000..1a9fc8d0 --- /dev/null +++ b/docker/1.4.10/docker-entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/ash + +set -e +exec "$@" + From 53616be0e296f6186f52c791e241c76d53380078 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 5 Jan 2017 21:32:41 +0000 Subject: [PATCH 05/37] Fix 1.4.10 docker files. --- docker/1.4.10/Dockerfile | 2 +- docker/1.4.10/README.md | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docker/1.4.10/Dockerfile b/docker/1.4.10/Dockerfile index ee55de18..3101650b 100644 --- a/docker/1.4.10/Dockerfile +++ b/docker/1.4.10/Dockerfile @@ -3,7 +3,7 @@ MAINTAINER David Audet LABEL Description="Eclipse Mosquitto MQTT Broker" -RUN apk --no-cache --update add mosquitto=1.4.10-r2 && \ +RUN apk --no-cache add mosquitto=1.4.10-r2 && \ mkdir -p /mosquitto/config /mosquitto/data /mosquitto/log && \ cp /etc/mosquitto/mosquitto.conf /mosquitto/config && \ chown -R mosquitto:mosquitto /mosquitto diff --git a/docker/1.4.10/README.md b/docker/1.4.10/README.md index fd8ae40a..537d8c2e 100644 --- a/docker/1.4.10/README.md +++ b/docker/1.4.10/README.md @@ -1,4 +1,4 @@ -#Eclipse Mosquitto v1.4.8 Docker Image +#Eclipse Mosquitto v1.4.10 Docker Image ##Mount Points @@ -15,7 +15,7 @@ Three mount points have been created in the image to be used for configuration, When running the image, the default configuration values are used. To use a custom configuration file, mount a **local** configuration file to `/mosquitto/conf/mosquitto.conf` ``` -docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf mosquitto:1.4.8 +docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf mosquitto:1.4.10 ``` Configuration can be changed to: @@ -36,13 +36,13 @@ log_dest file /mosquitto/log/mosquitto.log ##Build Build the image: ``` -docker build -t mosquitto:1.4.8 . +docker build -t mosquitto:1.4.10 . ``` ##Run Run a container using the new image: ``` -docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.8 +docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.10 ``` :boom: if the mosquitto configuration (mosquitto.conf) was modified to use non-default ports, the docker run command will need to be updated From a8194f0c2d0b005724a33cd7d8c7b54ef39eaa8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Bogda=C5=82?= Date: Sat, 21 Jan 2017 09:22:13 +0100 Subject: [PATCH 06/37] Update docker config path (#349) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adam BogdaƂ --- docker/1.4.10/README.md | 6 +++--- docker/1.4.4/README.md | 6 +++--- docker/1.4.8/README.md | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docker/1.4.10/README.md b/docker/1.4.10/README.md index 537d8c2e..bc8dfb72 100644 --- a/docker/1.4.10/README.md +++ b/docker/1.4.10/README.md @@ -13,9 +13,9 @@ Three mount points have been created in the image to be used for configuration, ##Configuration When running the image, the default configuration values are used. -To use a custom configuration file, mount a **local** configuration file to `/mosquitto/conf/mosquitto.conf` +To use a custom configuration file, mount a **local** configuration file to `/mosquitto/config/mosquitto.conf` ``` -docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf mosquitto:1.4.10 +docker run -it -p 1883:1883 -p 9001:9001 -v :/mosquitto/config/mosquitto.conf mosquitto:1.4.10 ``` Configuration can be changed to: @@ -42,7 +42,7 @@ docker build -t mosquitto:1.4.10 . ##Run Run a container using the new image: ``` -docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.10 +docker run -it -p 1883:1883 -p 9001:9001 -v :/mosquitto/config/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.10 ``` :boom: if the mosquitto configuration (mosquitto.conf) was modified to use non-default ports, the docker run command will need to be updated diff --git a/docker/1.4.4/README.md b/docker/1.4.4/README.md index 795dd2b1..dd4fbbb8 100644 --- a/docker/1.4.4/README.md +++ b/docker/1.4.4/README.md @@ -13,9 +13,9 @@ Three mount points have been created in the image to be used for configuration, ##Configuration When running the image, the default configuration values are used. -To use a custom configuration file, mount a **local** configuration file to `/mosquitto/conf/mosquitto.conf` +To use a custom configuration file, mount a **local** configuration file to `/mosquitto/config/mosquitto.conf` ``` -docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf mosquitto:1.4.4 +docker run -it -p 1883:1883 -p 9001:9001 -v :/mosquitto/config/mosquitto.conf mosquitto:1.4.4 ``` Configuration can be changed to: @@ -42,7 +42,7 @@ docker build -t mosquitto:1.4.4 . ##Run Run a container using the new image: ``` -docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.4 +docker run -it -p 1883:1883 -p 9001:9001 -v :/mosquitto/config/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.4 ``` :boom: if the mosquitto configuration (mosquitto.conf) was modified to use non-default ports, the docker run command will need to be updated diff --git a/docker/1.4.8/README.md b/docker/1.4.8/README.md index fd8ae40a..811d01f7 100644 --- a/docker/1.4.8/README.md +++ b/docker/1.4.8/README.md @@ -13,9 +13,9 @@ Three mount points have been created in the image to be used for configuration, ##Configuration When running the image, the default configuration values are used. -To use a custom configuration file, mount a **local** configuration file to `/mosquitto/conf/mosquitto.conf` +To use a custom configuration file, mount a **local** configuration file to `/mosquitto/config/mosquitto.conf` ``` -docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf mosquitto:1.4.8 +docker run -it -p 1883:1883 -p 9001:9001 -v :/mosquitto/config/mosquitto.conf mosquitto:1.4.8 ``` Configuration can be changed to: @@ -42,7 +42,7 @@ docker build -t mosquitto:1.4.8 . ##Run Run a container using the new image: ``` -docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/data/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.8 +docker run -it -p 1883:1883 -p 9001:9001 -v :/mosquitto/config/mosquitto.conf -v /mosquitto/data -v /mosquitto/log mosquitto:1.4.8 ``` :boom: if the mosquitto configuration (mosquitto.conf) was modified to use non-default ports, the docker run command will need to be updated From 20197e24967a623a31b221d88296601fbe7e2752 Mon Sep 17 00:00:00 2001 From: Karl Palsson Date: Thu, 8 Sep 2016 11:24:29 +0000 Subject: [PATCH 07/37] websockets: fix compatibility with older lws versions (#260) In 1.3, 1.4 and 1.5, the function was "libwebsockets_get_protocol" not "libwebsocket_get_protocol" While the #define name doesn't matter on newer libwebsockets, where it redirects to lws_get_protocol, the naming is critical for older versions. Fixes: 477cd3e39911 (Fix missing context->listener for websocket client) Signed-off-by: Karl Palsson --- src/mosquitto_broker.h | 2 +- src/websockets.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mosquitto_broker.h b/src/mosquitto_broker.h index 7d29e927..bd6a0ef7 100644 --- a/src/mosquitto_broker.h +++ b/src/mosquitto_broker.h @@ -31,7 +31,7 @@ Contributors: # define libwebsocket_write(A, B, C, D) lws_write((A), (B), (C), (D)) # define libwebsocket_get_socket_fd(A) lws_get_socket_fd((A)) # define libwebsockets_return_http_status(A, B, C, D) lws_return_http_status((B), (C), (D)) -# define libwebsocket_get_protocol(A) lws_get_protocol((A)) +# define libwebsockets_get_protocol(A) lws_get_protocol((A)) # define libwebsocket_context lws_context # define libwebsocket_protocols lws_protocols diff --git a/src/websockets.c b/src/websockets.c index c16bde7a..231cb72b 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -182,7 +182,7 @@ static int callback_mqtt(struct libwebsocket_context *context, case LWS_CALLBACK_ESTABLISHED: mosq = mqtt3_context_init(db, WEBSOCKET_CLIENT); if(mosq){ - p = libwebsocket_get_protocol(wsi); + p = libwebsockets_get_protocol(wsi); for (i=0; iconfig->listener_count; i++){ if (db->config->listeners[i].protocol == mp_websockets) { for (j=0; db->config->listeners[i].ws_protocol[j].name; j++){ From 6b68371dbe7ec7d77ca4dc2aa3b4fe403d782ab7 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 20 Sep 2016 23:26:14 +0100 Subject: [PATCH 08/37] [259] Fix crash when "lazy" type bridge attempts to reconnect. Thanks to hakofugu41. Bug: https://github.com/eclipse/mosquitto/issues/259 --- ChangeLog.txt | 3 +++ src/loop.c | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index bec39d77..0899f8a7 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,6 @@ +Broker: +- Fix crash when "lazy" type bridge attempts to reconnect. Closes #259. + 1.4.10 - 20160816 ================= diff --git a/src/loop.c b/src/loop.c index 4470323d..07e02c5b 100644 --- a/src/loop.c +++ b/src/loop.c @@ -246,7 +246,16 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li }else{ if(context->bridge->start_type == bst_lazy && context->bridge->lazy_reconnect){ rc = mqtt3_bridge_connect(db, context); - if(rc){ + if(rc == MOSQ_ERR_SUCCESS){ + pollfds[pollfd_index].fd = context->sock; + pollfds[pollfd_index].events = POLLIN; + pollfds[pollfd_index].revents = 0; + if(context->current_out_packet){ + pollfds[pollfd_index].events |= POLLOUT; + } + context->pollfd_index = pollfd_index; + pollfd_index++; + }else{ context->bridge->cur_address++; if(context->bridge->cur_address == context->bridge->address_count){ context->bridge->cur_address = 0; From 9f743d597268f52dcafcd5c5a936526a6ab93d80 Mon Sep 17 00:00:00 2001 From: tucic Date: Thu, 29 Sep 2016 19:51:31 +0200 Subject: [PATCH 09/37] Maximum connections for websockets listener (#271) Check current number of connections before accepting new websockets clients. Signed-off-by: tucic --- src/websockets.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/websockets.c b/src/websockets.c index 231cb72b..975a10c0 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -193,7 +193,10 @@ static int callback_mqtt(struct libwebsocket_context *context, } } } - + if(!mosq->listener){ + _mosquitto_free(mosq); + return -1; + } #if !defined(LWS_LIBRARY_VERSION_NUMBER) mosq->ws_context = context; #endif @@ -209,6 +212,12 @@ static int callback_mqtt(struct libwebsocket_context *context, u->mosq = NULL; return -1; } + if(mosq->listener->max_connections > 0 && mosq->listener->client_count > mosq->listener->max_connections){ + _mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "Client connection from %s denied: max_connections exceeded.", mosq->address); + _mosquitto_free(mosq); + u->mosq = NULL; + return -1; + } break; case LWS_CALLBACK_CLOSED: From 2c5785376ba12a4c34a113e2322984e30f3d9c06 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 29 Sep 2016 21:08:02 +0100 Subject: [PATCH 10/37] Update changelog. --- ChangeLog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 0899f8a7..57eb6af1 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,6 @@ Broker: - Fix crash when "lazy" type bridge attempts to reconnect. Closes #259. +- maximum_connections now applies to websockets listeners. Closes #271. 1.4.10 - 20160816 ================= From ed80a9a5261e0ca667dfb4c5609364066ec7b869 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 20 Oct 2016 13:47:41 +0100 Subject: [PATCH 11/37] [295] Usage should say we support 3.1.1 as well as 3.1. Closes #295. Bug: https://github.com/eclipse/mosquitto/issues/295 --- src/conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conf.c b/src/conf.c index 587e970b..4f4732f2 100644 --- a/src/conf.c +++ b/src/conf.c @@ -309,7 +309,7 @@ void mqtt3_config_cleanup(struct mqtt3_config *config) static void print_usage(void) { printf("mosquitto version %s (build date %s)\n\n", VERSION, TIMESTAMP); - printf("mosquitto is an MQTT v3.1 broker.\n\n"); + printf("mosquitto is an MQTT v3.1.1/v3.1 broker.\n\n"); printf("Usage: mosquitto [-c config_file] [-d] [-h] [-p port]\n\n"); printf(" -c : specify the broker config file.\n"); printf(" -d : put the broker into the background after starting.\n"); From 98ea68490626b1d18aee2004b411294c85e62212 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 30 Nov 2016 11:31:30 +0000 Subject: [PATCH 12/37] [323] Allow outgoing IPv6 connections to use TLS. Bug: https://github.com/eclipse/mosquitto/issues/323 --- ChangeLog.txt | 5 +++++ lib/net_mosq.c | 10 ++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 57eb6af1..7cb1a5fb 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,11 @@ Broker: - Fix crash when "lazy" type bridge attempts to reconnect. Closes #259. - maximum_connections now applies to websockets listeners. Closes #271. +- Allow bridges to use TLS with IPv6. + +Client library: +- Clients can now use TLS with IPv6. + 1.4.10 - 20160816 ================= diff --git a/lib/net_mosq.c b/lib/net_mosq.c index f18d41b2..26f98554 100644 --- a/lib/net_mosq.c +++ b/lib/net_mosq.c @@ -281,14 +281,7 @@ int _mosquitto_try_connect(struct mosquitto *mosq, const char *host, uint16_t po *sock = INVALID_SOCKET; memset(&hints, 0, sizeof(struct addrinfo)); -#ifdef WITH_TLS - if(mosq->tls_cafile || mosq->tls_capath || mosq->tls_psk){ - hints.ai_family = PF_INET; - }else -#endif - { - hints.ai_family = PF_UNSPEC; - } + hints.ai_family = PF_UNSPEC; hints.ai_flags = AI_ADDRCONFIG; hints.ai_socktype = SOCK_STREAM; @@ -542,6 +535,7 @@ int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t COMPAT_CLOSE(sock); return MOSQ_ERR_TLS; } + SSL_set_ex_data(mosq->ssl, tls_ex_index_mosq, mosq); bio = BIO_new_socket(sock, BIO_NOCLOSE); if(!bio){ From 4dc96a253316a643379f54f5c292690e8c7998dc Mon Sep 17 00:00:00 2001 From: Teun Lassche Date: Mon, 7 Nov 2016 20:28:17 +0100 Subject: [PATCH 13/37] Fix #304 Socket leakage Signed-off-by: Teun Lassche --- lib/mosquitto.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/mosquitto.c b/lib/mosquitto.c index 880657df..732e18f3 100644 --- a/lib/mosquitto.c +++ b/lib/mosquitto.c @@ -520,6 +520,10 @@ static int _mosquitto_reconnect(struct mosquitto *mosq, bool blocking) _mosquitto_messages_reconnect_reset(mosq); + if(mosq->sock != INVALID_SOCKET){ + _mosquitto_socket_close(mosq); //close socket + } + #ifdef WITH_SOCKS if(mosq->socks5_host){ rc = _mosquitto_socket_connect(mosq, mosq->socks5_host, mosq->socks5_port, mosq->bind_address, blocking); From 66683b96b0b45c690f009bf4c0fcea7f374d2a8c Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sun, 4 Dec 2016 22:01:20 +0000 Subject: [PATCH 14/37] Fix potential socket leakage when reconnecting. Bug: https://github.com/eclipse/mosquitto/issues/304 --- ChangeLog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 7cb1a5fb..d7cdf92c 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -5,6 +5,7 @@ Broker: Client library: - Clients can now use TLS with IPv6. +- Fix potential socket leakage when reconnecting. Closes #304. 1.4.10 - 20160816 From 8e4a80a92802fc5b5fb0ef774caeb424536e3f16 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 8 Dec 2016 21:06:45 +0000 Subject: [PATCH 15/37] [329] Fix potential negative timeout being passed to pselect. Thanks to Dollars. Bug: https://github.com/eclipse/mosquitto/issues/329 --- ChangeLog.txt | 1 + lib/mosquitto.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index d7cdf92c..45fbd33d 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -6,6 +6,7 @@ Broker: Client library: - Clients can now use TLS with IPv6. - Fix potential socket leakage when reconnecting. Closes #304. +- Fix potential negative timeout being passed to pselect. Closes #329. 1.4.10 - 20160816 diff --git a/lib/mosquitto.c b/lib/mosquitto.c index 732e18f3..afd7e375 100644 --- a/lib/mosquitto.c +++ b/lib/mosquitto.c @@ -916,6 +916,12 @@ int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets) timeout = (mosq->next_msg_out - now)*1000; } + if(timeout < 0){ + /* There has been a delay somewhere which means we should have already + * sent a message. */ + timeout = 0; + } + local_timeout.tv_sec = timeout/1000; #ifdef HAVE_PSELECT local_timeout.tv_nsec = (timeout-local_timeout.tv_sec*1000)*1e6; From b9d4ebfba38095614349b20b8837ab4f970b224b Mon Sep 17 00:00:00 2001 From: Jens Breitbart Date: Sat, 10 Dec 2016 19:41:38 +0100 Subject: [PATCH 16/37] Fix compiler warnings (unused parameter, additional semicolon). A modern version of the clang compiler complained about: * unused parameters * additional semicolon . This commit fixes these warnings. Signed-off-by: Jens Breitbart --- lib/cpp/mosquittopp.h | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/cpp/mosquittopp.h b/lib/cpp/mosquittopp.h index d3d6f13e..e54805d3 100644 --- a/lib/cpp/mosquittopp.h +++ b/lib/cpp/mosquittopp.h @@ -4,12 +4,12 @@ Copyright (c) 2010-2013 Roger Light 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: Roger Light - initial implementation and documentation. */ @@ -28,8 +28,8 @@ Contributors: #endif #include -#include #include +#include namespace mosqpp { @@ -90,15 +90,16 @@ class mosqpp_EXPORT mosquittopp { bool want_write(); int threaded_set(bool threaded=true); int socks5_set(const char *host, int port=1080, const char *username=NULL, const char *password=NULL); - - virtual void on_connect(int rc) {return;}; - virtual void on_disconnect(int rc) {return;}; - virtual void on_publish(int mid) {return;}; - virtual void on_message(const struct mosquitto_message *message) {return;}; - virtual void on_subscribe(int mid, int qos_count, const int *granted_qos) {return;}; - virtual void on_unsubscribe(int mid) {return;}; - virtual void on_log(int level, const char *str) {return;}; - virtual void on_error() {return;}; + + // names in the functions commented to prevent unused parameter warning + virtual void on_connect(int /*rc*/) {return;} + virtual void on_disconnect(int /*rc*/) {return;} + virtual void on_publish(int /*mid*/) {return;} + virtual void on_message(const struct mosquitto_message * /*message*/) {return;} + virtual void on_subscribe(int /*mid*/, int /*qos_count*/, const int * /*granted_qos*/) {return;} + virtual void on_unsubscribe(int /*mid*/) {return;} + virtual void on_log(int /*level*/, const char * /*str*/) {return;} + virtual void on_error() {return;} }; } From b5b5e6f27db2722a5482e754946f8d1eee3bd902 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 5 Jan 2017 21:42:24 +0000 Subject: [PATCH 17/37] Don't use reserved identifiers in public headers. --- lib/cpp/mosquittopp.h | 4 ++-- lib/mosquitto.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/cpp/mosquittopp.h b/lib/cpp/mosquittopp.h index e54805d3..9b0cb694 100644 --- a/lib/cpp/mosquittopp.h +++ b/lib/cpp/mosquittopp.h @@ -14,8 +14,8 @@ Contributors: Roger Light - initial implementation and documentation. */ -#ifndef _MOSQUITTOPP_H_ -#define _MOSQUITTOPP_H_ +#ifndef MOSQUITTOPP_H +#define MOSQUITTOPP_H #ifdef _WIN32 # ifdef mosquittopp_EXPORTS diff --git a/lib/mosquitto.h b/lib/mosquitto.h index a7de2922..2058d59a 100644 --- a/lib/mosquitto.h +++ b/lib/mosquitto.h @@ -14,8 +14,8 @@ Contributors: Roger Light - initial implementation and documentation. */ -#ifndef _MOSQUITTO_H_ -#define _MOSQUITTO_H_ +#ifndef MOSQUITTO_H +#define MOSQUITTO_H #ifdef __cplusplus extern "C" { From 7279e481911f282b06e095b84144f1e1570e6947 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Fri, 6 Jan 2017 00:44:17 +0000 Subject: [PATCH 18/37] [316] Don't error on zero length persistence files. Closes #316. Bug: https://github.com/eclipse/mosquitto/issues/316 --- ChangeLog.txt | 1 + src/persist.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 45fbd33d..c1d6cbfc 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -2,6 +2,7 @@ Broker: - Fix crash when "lazy" type bridge attempts to reconnect. Closes #259. - maximum_connections now applies to websockets listeners. Closes #271. - Allow bridges to use TLS with IPv6. +- Don't error on zero length persistence files. Closes #316. Client library: - Clients can now use TLS with IPv6. diff --git a/src/persist.c b/src/persist.c index 47c27ae7..dad6830f 100644 --- a/src/persist.c +++ b/src/persist.c @@ -813,7 +813,14 @@ int mqtt3_db_restore(struct mosquitto_db *db) fptr = _mosquitto_fopen(db->config->persistence_filepath, "rb"); if(fptr == NULL) return MOSQ_ERR_SUCCESS; - read_e(fptr, &header, 15); + rlen = fread(&header, 1, 15, fptr); + if(rlen == 0){ + fclose(fptr); + _mosquitto_log_printf(NULL, MOSQ_LOG_WARNING, "Warning: Persistence file is empty."); + return 0; + }else if(rlen != 15){ + goto error; + } if(!memcmp(header, magic, 15)){ // Restore DB as normal read_e(fptr, &crc, sizeof(uint32_t)); From b01e32bd8b67802ba9f0b3533d4769755a538b33 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Fri, 20 Jan 2017 18:25:04 +0000 Subject: [PATCH 19/37] [354] Close http files even on bad clients. Thanks to jbwdevries. Bug: https://github.com/eclipse/mosquitto/issues/354 --- ChangeLog.txt | 2 ++ src/websockets.c | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index c1d6cbfc..9c9f6cd8 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -3,6 +3,8 @@ Broker: - maximum_connections now applies to websockets listeners. Closes #271. - Allow bridges to use TLS with IPv6. - Don't error on zero length persistence files. Closes #316. +- For http only websockets clients, close files served over http in all cases + when the client disconnects. Closes #354. Client library: - Clients can now use TLS with IPv6. diff --git a/src/websockets.c b/src/websockets.c index 975a10c0..529aaff4 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -521,6 +521,7 @@ static int callback_http(struct libwebsocket_context *context, (unsigned int)filestat.st_size); if(libwebsocket_write(wsi, buf, buflen, LWS_WRITE_HTTP) < 0){ fclose(u->fptr); + u->fptr = NULL; return -1; } libwebsocket_callback_on_writable(context, wsi); @@ -546,6 +547,7 @@ static int callback_http(struct libwebsocket_context *context, buflen = fread(buf, 1, sizeof(buf), u->fptr); if(buflen < 1){ fclose(u->fptr); + u->fptr = NULL; return -1; } wlen = libwebsocket_write(wsi, buf, buflen, LWS_WRITE_HTTP); @@ -566,6 +568,15 @@ static int callback_http(struct libwebsocket_context *context, }else{ return -1; } + + case LWS_CALLBACK_CLOSED: + case LWS_CALLBACK_CLOSED_HTTP: + case LWS_CALLBACK_HTTP_FILE_COMPLETION: + if(u && u->fptr){ + fclose(u->fptr); + u->fptr = NULL; + } + break; #endif default: From e7c1507f889d6b158568e43a3bfa6a4a4e0105c3 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Fri, 20 Jan 2017 21:18:18 +0000 Subject: [PATCH 20/37] Fix error message when websockets http_dir directory does not exist. --- ChangeLog.txt | 1 + src/websockets.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 9c9f6cd8..00dd0704 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -5,6 +5,7 @@ Broker: - Don't error on zero length persistence files. Closes #316. - For http only websockets clients, close files served over http in all cases when the client disconnects. Closes #354. +- Fix error message when websockets http_dir directory does not exist. Client library: - Clients can now use TLS with IPv6. diff --git a/src/websockets.c b/src/websockets.c index 529aaff4..bae69e03 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -656,7 +656,7 @@ struct libwebsocket_context *mosq_websockets_init(struct _mqtt3_listener *listen if(!user->http_dir){ _mosquitto_free(user); _mosquitto_free(p); - _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Unable to open http dir \"%s\".", user->http_dir); + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Unable to open http dir \"%s\".", listener->http_dir); return NULL; } } From 2c92d3b8371af70e5f10e74f26c321763fb9006d Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sat, 21 Jan 2017 07:50:07 +0000 Subject: [PATCH 21/37] More file closing fixes. --- src/websockets.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/websockets.c b/src/websockets.c index bae69e03..b44943d3 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -504,6 +504,7 @@ static int callback_http(struct libwebsocket_context *context, if(fstat(fileno(u->fptr), &filestat) < 0){ libwebsockets_return_http_status(context, wsi, HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL); fclose(u->fptr); + u->fptr = NULL; return -1; } #ifdef WIN32 @@ -512,6 +513,8 @@ static int callback_http(struct libwebsocket_context *context, if(!S_ISREG(filestat.st_mode)){ #endif libwebsockets_return_http_status(context, wsi, HTTP_STATUS_FORBIDDEN, NULL); + fclose(u->fptr); + u->fptr = NULL; return -1; } @@ -568,6 +571,7 @@ static int callback_http(struct libwebsocket_context *context, }else{ return -1; } + break; case LWS_CALLBACK_CLOSED: case LWS_CALLBACK_CLOSED_HTTP: From 35cc1eb21e94f57d50740bdcdd062f6d2ca49791 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Tue, 24 Jan 2017 23:01:16 +0100 Subject: [PATCH 22/37] Check for rt and pthread libraries before linking This fixes building on Android which does not have separate librt or libpthread libraries. Signed-off-by: Fredrik Fornwall --- lib/CMakeLists.txt | 12 ++++++++++-- src/CMakeLists.txt | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index d9163991..07be5d93 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -7,7 +7,12 @@ if (${WITH_THREADING} STREQUAL ON) set (PTHREAD_LIBRARIES C:\\pthreads\\Pre-built.2\\lib\\x86\\pthreadVC2.lib) set (PTHREAD_INCLUDE_DIR C:\\pthreads\\Pre-built.2\\include) else (WIN32) - set (PTHREAD_LIBRARIES pthread) + find_library(LIBPTHREAD pthread) + if (LIBPTHREAD) + set (PTHREAD_LIBRARIES pthread) + else (LIBPTHREAD) + set (PTHREAD_LIBRARIES "") + endif() set (PTHREAD_INCLUDE_DIR "") endif (WIN32) else (${WITH_THREADING} STREQUAL ON) @@ -44,7 +49,10 @@ add_library(libmosquitto SHARED set (LIBRARIES ${OPENSSL_LIBRARIES} ${PTHREAD_LIBRARIES}) if (UNIX AND NOT APPLE) - set (LIBRARIES ${LIBRARIES} rt) + find_library(LIBRT rt) + if (LIBRT) + set (LIBRARIES ${LIBRARIES} rt) + endif (LIBRT) endif (UNIX AND NOT APPLE) if (WIN32) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0008e555..9d615636 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -86,7 +86,11 @@ if (UNIX) if (APPLE) set (MOSQ_LIBS ${MOSQ_LIBS} dl m) else (APPLE) - set (MOSQ_LIBS ${MOSQ_LIBS} rt dl m) + set (MOSQ_LIBS ${MOSQ_LIBS} dl m) + find_library(LIBRT rt) + if (LIBRT) + set (MOSQ_LIBS ${MOSQ_LIBS} rt) + endif (LIBRT) endif (APPLE) endif (UNIX) From 54a467d7828394dd76645d40ff5c58b67cc16e59 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Tue, 24 Jan 2017 23:24:22 +0100 Subject: [PATCH 23/37] Include instead of Using the standard header instead of makes it consistent with other source files and fixes compilation on Android. Signed-off-by: Fredrik Fornwall --- src/conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conf.c b/src/conf.c index 4f4732f2..9792b2ea 100644 --- a/src/conf.c +++ b/src/conf.c @@ -36,7 +36,7 @@ Contributors: #endif #if !defined(WIN32) && !defined(__CYGWIN__) -# include +# include #endif #include From e2edba054e880bcf94335468468fb3de5b4439b3 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 2 Feb 2017 14:12:59 +0000 Subject: [PATCH 24/37] Fix build dep typo. --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index a00fe0d4..9515380d 100644 --- a/readme.md +++ b/readme.md @@ -65,7 +65,7 @@ already be built. Use `make binary` to skip building the man pages, or install ### Build Dependencies -* c-ares (libc-ares2-dev on Debian based systems) - disable with `make WITH_DNS_SRV=no` +* c-ares (libc-ares-dev on Debian based systems) - disable with `make WITH_DNS_SRV=no` * libuuid (uuid-dev) - disable with `make WITH_UUID=no` * libwebsockets (libwebsockets-dev) - enable with `make WITH_LIBWEBSOCKETS=yes` * openssl (libssl-dev on Debian based systems) - disable with `make WITH_TLS=no` From e13af18ed9c527b8152697c9ede62f0e4e81bdd6 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 6 Feb 2017 22:39:39 +0000 Subject: [PATCH 25/37] Start of fix for [344]. --- config.mk | 4 ++ lib/mosquitto_internal.h | 6 ++ lib/net_mosq.c | 140 ++++++++++++++++++++++++++++++++------- lib/net_mosq.h | 2 + src/bridge.c | 44 +++++++++++- src/loop.c | 78 +++++++++++++--------- src/mosquitto_broker.h | 2 + 7 files changed, 217 insertions(+), 59 deletions(-) diff --git a/config.mk b/config.mk index 087766c5..3d2aa499 100644 --- a/config.mk +++ b/config.mk @@ -156,6 +156,10 @@ ifeq ($(UNAME),QNX) LIB_LIBS:=$(LIB_LIBS) -lsocket endif +ifeq ($(UNAME),Linux) + BROKER_LIBS:=$(BROKER_LIBS) -lanl +endif + ifeq ($(WITH_WRAP),yes) BROKER_LIBS:=$(BROKER_LIBS) -lwrap BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_WRAP diff --git a/lib/mosquitto_internal.h b/lib/mosquitto_internal.h index 4b4cf858..640de160 100644 --- a/lib/mosquitto_internal.h +++ b/lib/mosquitto_internal.h @@ -56,6 +56,9 @@ Contributors: #include "mosquitto.h" #include "time_mosq.h" #ifdef WITH_BROKER +# ifdef __linux__ +# include +# endif # include "uthash.h" struct mosquitto_client_msg; #endif @@ -151,6 +154,9 @@ struct mosquitto { mosq_sock_t sock; #ifndef WITH_BROKER mosq_sock_t sockpairR, sockpairW; +#endif +#ifdef __linux__ + struct gaicb *adns; /* For getaddrinfo_a */ #endif enum _mosquitto_protocol protocol; char *address; diff --git a/lib/net_mosq.c b/lib/net_mosq.c index 26f98554..24174f09 100644 --- a/lib/net_mosq.c +++ b/lib/net_mosq.c @@ -14,12 +14,15 @@ Contributors: Roger Light - initial implementation and documentation. */ +#define _GNU_SOURCE + #include #include #include #include #include #ifndef WIN32 +#define _GNU_SOURCE #include #include #include @@ -268,6 +271,88 @@ static unsigned int psk_client_callback(SSL *ssl, const char *hint, } #endif +#if defined(WITH_BROKER) && defined(__linux__) +/* Async connect, part 1 (dns lookup) */ +int _mosquitto_try_connect_step1(struct mosquitto *mosq, const char *host) +{ + int s; + void *sevp = NULL; + + if(mosq->adns){ + _mosquitto_free(mosq->adns); + } + mosq->adns = _mosquitto_calloc(1, sizeof(struct gaicb)); + if(!mosq->adns){ + return MOSQ_ERR_NOMEM; + } + mosq->adns->ar_name = host; + + s = getaddrinfo_a(GAI_NOWAIT, &mosq->adns, 1, sevp); + if(s){ + errno = s; + return MOSQ_ERR_EAI; + } + + return MOSQ_ERR_SUCCESS; +} + +/* Async connect part 2, the connection. */ +int _mosquitto_try_connect_step2(struct mosquitto *mosq, uint16_t port, mosq_sock_t *sock) +{ + struct addrinfo *ainfo, *rp; + int rc; + + ainfo = mosq->adns->ar_result; + + for(rp = ainfo; rp != NULL; rp = rp->ai_next){ + *sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); + if(*sock == INVALID_SOCKET) continue; + + if(rp->ai_family == PF_INET){ + ((struct sockaddr_in *)rp->ai_addr)->sin_port = htons(port); + }else if(rp->ai_family == PF_INET6){ + ((struct sockaddr_in6 *)rp->ai_addr)->sin6_port = htons(port); + }else{ + COMPAT_CLOSE(*sock); + continue; + } + + /* Set non-blocking */ + if(_mosquitto_socket_nonblock(*sock)){ + COMPAT_CLOSE(*sock); + continue; + } + + rc = connect(*sock, rp->ai_addr, rp->ai_addrlen); +#ifdef WIN32 + errno = WSAGetLastError(); +#endif + if(rc == 0 || errno == EINPROGRESS || errno == COMPAT_EWOULDBLOCK){ + if(rc < 0 && (errno == EINPROGRESS || errno == COMPAT_EWOULDBLOCK)){ + rc = MOSQ_ERR_CONN_PENDING; + } + + /* Set non-blocking */ + if(_mosquitto_socket_nonblock(*sock)){ + COMPAT_CLOSE(*sock); + continue; + } + break; + } + + COMPAT_CLOSE(*sock); + *sock = INVALID_SOCKET; + } + freeaddrinfo(ainfo); + if(!rp){ + return MOSQ_ERR_ERRNO; + } + return rc; +} + +#endif + + int _mosquitto_try_connect(struct mosquitto *mosq, const char *host, uint16_t port, mosq_sock_t *sock, const char *bind_address, bool blocking) { struct addrinfo hints; @@ -303,7 +388,7 @@ int _mosquitto_try_connect(struct mosquitto *mosq, const char *host, uint16_t po for(rp = ainfo; rp != NULL; rp = rp->ai_next){ *sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); if(*sock == INVALID_SOCKET) continue; - + if(rp->ai_family == PF_INET){ ((struct sockaddr_in *)rp->ai_addr)->sin_port = htons(port); }else if(rp->ai_family == PF_INET6){ @@ -396,24 +481,13 @@ int mosquitto__socket_connect_tls(struct mosquitto *mosq) } #endif -/* Create a socket and connect it to 'ip' on port 'port'. - * Returns -1 on failure (ip is NULL, socket creation/connection error) - * Returns sock number on success. - */ -int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking) +int _mosquitto_socket_connect_step3(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking) { - mosq_sock_t sock = INVALID_SOCKET; - int rc; #ifdef WITH_TLS int ret; BIO *bio; #endif - if(!mosq || !host || !port) return MOSQ_ERR_INVAL; - - rc = _mosquitto_try_connect(mosq, host, port, &sock, bind_address, blocking); - if(rc > 0) return rc; - #ifdef WITH_TLS if(mosq->tls_cafile || mosq->tls_capath || mosq->tls_psk){ #if OPENSSL_VERSION_NUMBER >= 0x10001000L @@ -425,7 +499,7 @@ int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t mosq->ssl_ctx = SSL_CTX_new(TLSv1_client_method()); }else{ _mosquitto_log_printf(mosq, MOSQ_LOG_ERR, "Error: Protocol %s not supported.", mosq->tls_version); - COMPAT_CLOSE(sock); + COMPAT_CLOSE(mosq->sock); return MOSQ_ERR_INVAL; } #else @@ -433,13 +507,13 @@ int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t mosq->ssl_ctx = SSL_CTX_new(TLSv1_client_method()); }else{ _mosquitto_log_printf(mosq, MOSQ_LOG_ERR, "Error: Protocol %s not supported.", mosq->tls_version); - COMPAT_CLOSE(sock); + COMPAT_CLOSE(mosq->sock); return MOSQ_ERR_INVAL; } #endif if(!mosq->ssl_ctx){ _mosquitto_log_printf(mosq, MOSQ_LOG_ERR, "Error: Unable to create TLS context."); - COMPAT_CLOSE(sock); + COMPAT_CLOSE(mosq->sock); return MOSQ_ERR_TLS; } @@ -456,7 +530,7 @@ int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t ret = SSL_CTX_set_cipher_list(mosq->ssl_ctx, mosq->tls_ciphers); if(ret == 0){ _mosquitto_log_printf(mosq, MOSQ_LOG_ERR, "Error: Unable to set TLS ciphers. Check cipher list \"%s\".", mosq->tls_ciphers); - COMPAT_CLOSE(sock); + COMPAT_CLOSE(mosq->sock); return MOSQ_ERR_TLS; } } @@ -480,7 +554,7 @@ int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t _mosquitto_log_printf(mosq, MOSQ_LOG_ERR, "Error: Unable to load CA certificates, check capath \"%s\".", mosq->tls_capath); } #endif - COMPAT_CLOSE(sock); + COMPAT_CLOSE(mosq->sock); return MOSQ_ERR_TLS; } if(mosq->tls_cert_reqs == 0){ @@ -502,7 +576,7 @@ int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t #else _mosquitto_log_printf(mosq, MOSQ_LOG_ERR, "Error: Unable to load client certificate \"%s\".", mosq->tls_certfile); #endif - COMPAT_CLOSE(sock); + COMPAT_CLOSE(mosq->sock); return MOSQ_ERR_TLS; } } @@ -514,13 +588,13 @@ int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t #else _mosquitto_log_printf(mosq, MOSQ_LOG_ERR, "Error: Unable to load client key file \"%s\".", mosq->tls_keyfile); #endif - COMPAT_CLOSE(sock); + COMPAT_CLOSE(mosq->sock); return MOSQ_ERR_TLS; } ret = SSL_CTX_check_private_key(mosq->ssl_ctx); if(ret != 1){ _mosquitto_log_printf(mosq, MOSQ_LOG_ERR, "Error: Client certificate/key are inconsistent."); - COMPAT_CLOSE(sock); + COMPAT_CLOSE(mosq->sock); return MOSQ_ERR_TLS; } } @@ -532,27 +606,43 @@ int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t mosq->ssl = SSL_new(mosq->ssl_ctx); if(!mosq->ssl){ - COMPAT_CLOSE(sock); + COMPAT_CLOSE(mosq->sock); return MOSQ_ERR_TLS; } SSL_set_ex_data(mosq->ssl, tls_ex_index_mosq, mosq); - bio = BIO_new_socket(sock, BIO_NOCLOSE); + bio = BIO_new_socket(mosq->sock, BIO_NOCLOSE); if(!bio){ - COMPAT_CLOSE(sock); + COMPAT_CLOSE(mosq->sock); return MOSQ_ERR_TLS; } SSL_set_bio(mosq->ssl, bio, bio); - mosq->sock = sock; if(mosquitto__socket_connect_tls(mosq)){ return MOSQ_ERR_TLS; } } #endif + return MOSQ_ERR_SUCCESS; +} + +/* Create a socket and connect it to 'ip' on port 'port'. + * Returns -1 on failure (ip is NULL, socket creation/connection error) + * Returns sock number on success. + */ +int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking) +{ + mosq_sock_t sock = INVALID_SOCKET; + int rc; + + if(!mosq || !host || !port) return MOSQ_ERR_INVAL; + + rc = _mosquitto_try_connect(mosq, host, port, &sock, bind_address, blocking); + if(rc > 0) return rc; mosq->sock = sock; + rc = _mosquitto_socket_connect_step3(mosq, host, port, bind_address, blocking); return rc; } diff --git a/lib/net_mosq.h b/lib/net_mosq.h index b101746d..569e9452 100644 --- a/lib/net_mosq.h +++ b/lib/net_mosq.h @@ -61,6 +61,8 @@ int _mosquitto_socket_close(struct mosquitto_db *db, struct mosquitto *mosq); int _mosquitto_socket_close(struct mosquitto *mosq); #endif int _mosquitto_try_connect(struct mosquitto *mosq, const char *host, uint16_t port, mosq_sock_t *sock, const char *bind_address, bool blocking); +int _mosquitto_try_connect_step1(struct mosquitto *mosq, const char *host); +int _mosquitto_try_connect_step2(struct mosquitto *mosq, uint16_t port, mosq_sock_t *sock); int _mosquitto_socket_nonblock(mosq_sock_t sock); int _mosquitto_socketpair(mosq_sock_t *sp1, mosq_sock_t *sp2); diff --git a/src/bridge.c b/src/bridge.c index a7d5ad09..e9a3d0ee 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -131,10 +131,15 @@ int mqtt3_bridge_new(struct mosquitto_db *db, struct _mqtt3_bridge *bridge) return MOSQ_ERR_NOMEM; } +#ifdef __linux__ + new_context->bridge->restart_t = 1; /* force quick restart of bridge */ + return mqtt3_bridge_connect_step1(db, new_context); +#else return mqtt3_bridge_connect(db, new_context); +#endif } -int mqtt3_bridge_connect(struct mosquitto_db *db, struct mosquitto *context) +int mqtt3_bridge_connect_step1(struct mosquitto_db *db, struct mosquitto *context) { int rc; int i; @@ -207,6 +212,31 @@ int mqtt3_bridge_connect(struct mosquitto_db *db, struct mosquitto *context) } } + _mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "Connecting bridge %s (%s:%d)", context->bridge->name, context->bridge->addresses[context->bridge->cur_address].address, context->bridge->addresses[context->bridge->cur_address].port); + rc = _mosquitto_try_connect_step1(context, context->bridge->addresses[context->bridge->cur_address].address); + if(rc > 0 ){ + if(rc == MOSQ_ERR_TLS){ + _mosquitto_socket_close(db, context); + return rc; /* Error already printed */ + }else if(rc == MOSQ_ERR_ERRNO){ + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error creating bridge: %s.", strerror(errno)); + }else if(rc == MOSQ_ERR_EAI){ + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error creating bridge: %s.", gai_strerror(errno)); + } + + return rc; + } + + return MOSQ_ERR_SUCCESS; +} + + +int mqtt3_bridge_connect_step2(struct mosquitto_db *db, struct mosquitto *context) +{ + int rc; + + if(!context || !context->bridge) return MOSQ_ERR_INVAL; + _mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "Connecting bridge %s (%s:%d)", context->bridge->name, context->bridge->addresses[context->bridge->cur_address].address, context->bridge->addresses[context->bridge->cur_address].port); rc = _mosquitto_socket_connect(context, context->bridge->addresses[context->bridge->cur_address].address, context->bridge->addresses[context->bridge->cur_address].port, NULL, false); if(rc > 0 ){ @@ -245,6 +275,18 @@ int mqtt3_bridge_connect(struct mosquitto_db *db, struct mosquitto *context) } } + +int mqtt3_bridge_connect(struct mosquitto_db *db, struct mosquitto *context) +{ + int rc; + + rc = mqtt3_bridge_connect_step1(db, context); + if(rc) return rc; + + return mqtt3_bridge_connect_step2(db, context); +} + + void mqtt3_bridge_packet_cleanup(struct mosquitto *context) { struct _mosquitto_packet *packet; diff --git a/src/loop.c b/src/loop.c index 07e02c5b..d3d5e6a8 100644 --- a/src/loop.c +++ b/src/loop.c @@ -244,45 +244,57 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li context->bridge->primary_retry = now + 5; } }else{ - if(context->bridge->start_type == bst_lazy && context->bridge->lazy_reconnect){ - rc = mqtt3_bridge_connect(db, context); - if(rc == MOSQ_ERR_SUCCESS){ - pollfds[pollfd_index].fd = context->sock; - pollfds[pollfd_index].events = POLLIN; - pollfds[pollfd_index].revents = 0; - if(context->current_out_packet){ - pollfds[pollfd_index].events |= POLLOUT; + if((context->bridge->start_type == bst_lazy && context->bridge->lazy_reconnect) + || (context->bridge->start_type == bst_automatic && now > context->bridge->restart_t)){ + +#ifdef __linux__ + if(context->adns){ + /* Waiting on DNS lookup */ + rc = mqtt3_bridge_connect_step2(db, context); + if(rc == MOSQ_ERR_SUCCESS){ + pollfds[pollfd_index].fd = context->sock; + pollfds[pollfd_index].events = POLLIN; + pollfds[pollfd_index].revents = 0; + if(context->current_out_packet){ + pollfds[pollfd_index].events |= POLLOUT; + } + context->pollfd_index = pollfd_index; + pollfd_index++; + }else{ + context->bridge->cur_address++; + if(context->bridge->cur_address == context->bridge->address_count){ + context->bridge->cur_address = 0; + } } - context->pollfd_index = pollfd_index; - pollfd_index++; }else{ - context->bridge->cur_address++; - if(context->bridge->cur_address == context->bridge->address_count){ - context->bridge->cur_address = 0; + rc = mqtt3_bridge_connect_step1(db, context); + if(rc){ + context->bridge->cur_address++; + if(context->bridge->cur_address == context->bridge->address_count){ + context->bridge->cur_address = 0; + } } } - } - if(context->bridge->start_type == bst_automatic && now > context->bridge->restart_t){ - context->bridge->restart_t = 0; - rc = mqtt3_bridge_connect(db, context); - if(rc == MOSQ_ERR_SUCCESS){ - pollfds[pollfd_index].fd = context->sock; - pollfds[pollfd_index].events = POLLIN; - pollfds[pollfd_index].revents = 0; - if(context->current_out_packet){ - pollfds[pollfd_index].events |= POLLOUT; - } - context->pollfd_index = pollfd_index; - pollfd_index++; - }else{ - /* Retry later. */ - context->bridge->restart_t = now+context->bridge->restart_timeout; - - context->bridge->cur_address++; - if(context->bridge->cur_address == context->bridge->address_count){ - context->bridge->cur_address = 0; +#else + { + rc = mqtt3_bridge_connect(db, context); + if(rc == MOSQ_ERR_SUCCESS){ + pollfds[pollfd_index].fd = context->sock; + pollfds[pollfd_index].events = POLLIN; + pollfds[pollfd_index].revents = 0; + if(context->current_out_packet){ + pollfds[pollfd_index].events |= POLLOUT; + } + context->pollfd_index = pollfd_index; + pollfd_index++; + }else{ + context->bridge->cur_address++; + if(context->bridge->cur_address == context->bridge->address_count){ + context->bridge->cur_address = 0; + } } } +#endif } } } diff --git a/src/mosquitto_broker.h b/src/mosquitto_broker.h index bd6a0ef7..c89489b6 100644 --- a/src/mosquitto_broker.h +++ b/src/mosquitto_broker.h @@ -466,6 +466,8 @@ int _mosquitto_log_printf(struct mosquitto *mosq, int level, const char *fmt, .. #ifdef WITH_BRIDGE int mqtt3_bridge_new(struct mosquitto_db *db, struct _mqtt3_bridge *bridge); int mqtt3_bridge_connect(struct mosquitto_db *db, struct mosquitto *context); +int mqtt3_bridge_connect_step1(struct mosquitto_db *db, struct mosquitto *context); +int mqtt3_bridge_connect_step2(struct mosquitto_db *db, struct mosquitto *context); void mqtt3_bridge_packet_cleanup(struct mosquitto *context); #endif From e0e8cc9f3e7c3b3d1e283250725a174ad3670ef7 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 6 Feb 2017 23:10:43 +0000 Subject: [PATCH 26/37] [344] Fix leaks and incorrect connect call. --- lib/net_mosq.h | 1 + src/bridge.c | 16 +++++++++++++++- src/loop.c | 36 ++++++++++++++++++++++++------------ 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/lib/net_mosq.h b/lib/net_mosq.h index 569e9452..b504ebc0 100644 --- a/lib/net_mosq.h +++ b/lib/net_mosq.h @@ -63,6 +63,7 @@ int _mosquitto_socket_close(struct mosquitto *mosq); int _mosquitto_try_connect(struct mosquitto *mosq, const char *host, uint16_t port, mosq_sock_t *sock, const char *bind_address, bool blocking); int _mosquitto_try_connect_step1(struct mosquitto *mosq, const char *host); int _mosquitto_try_connect_step2(struct mosquitto *mosq, uint16_t port, mosq_sock_t *sock); +int _mosquitto_socket_connect_step3(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking); int _mosquitto_socket_nonblock(mosq_sock_t sock); int _mosquitto_socketpair(mosq_sock_t *sp1, mosq_sock_t *sp2); diff --git a/src/bridge.c b/src/bridge.c index e9a3d0ee..5f5eb1b3 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -238,7 +238,21 @@ int mqtt3_bridge_connect_step2(struct mosquitto_db *db, struct mosquitto *contex if(!context || !context->bridge) return MOSQ_ERR_INVAL; _mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "Connecting bridge %s (%s:%d)", context->bridge->name, context->bridge->addresses[context->bridge->cur_address].address, context->bridge->addresses[context->bridge->cur_address].port); - rc = _mosquitto_socket_connect(context, context->bridge->addresses[context->bridge->cur_address].address, context->bridge->addresses[context->bridge->cur_address].port, NULL, false); + rc = _mosquitto_try_connect_step2(context, context->bridge->addresses[context->bridge->cur_address].port, &context->sock); + if(rc > 0 ){ + if(rc == MOSQ_ERR_TLS){ + _mosquitto_socket_close(db, context); + return rc; /* Error already printed */ + }else if(rc == MOSQ_ERR_ERRNO){ + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error creating bridge: %s.", strerror(errno)); + }else if(rc == MOSQ_ERR_EAI){ + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error creating bridge: %s.", gai_strerror(errno)); + } + + return rc; + } + + rc = _mosquitto_socket_connect_step3(context, context->bridge->addresses[context->bridge->cur_address].address, context->bridge->addresses[context->bridge->cur_address].port, NULL, false); if(rc > 0 ){ if(rc == MOSQ_ERR_TLS){ _mosquitto_socket_close(db, context); diff --git a/src/loop.c b/src/loop.c index d3d5e6a8..a4014f0c 100644 --- a/src/loop.c +++ b/src/loop.c @@ -250,21 +250,33 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li #ifdef __linux__ if(context->adns){ /* Waiting on DNS lookup */ - rc = mqtt3_bridge_connect_step2(db, context); - if(rc == MOSQ_ERR_SUCCESS){ - pollfds[pollfd_index].fd = context->sock; - pollfds[pollfd_index].events = POLLIN; - pollfds[pollfd_index].revents = 0; - if(context->current_out_packet){ - pollfds[pollfd_index].events |= POLLOUT; + rc = gai_error(context->adns); + if(rc == EAI_INPROGRESS){ + /* Just keep on waiting */ + }else if(rc == 0){ + rc = mqtt3_bridge_connect_step2(db, context); + if(rc == MOSQ_ERR_SUCCESS){ + pollfds[pollfd_index].fd = context->sock; + pollfds[pollfd_index].events = POLLIN; + pollfds[pollfd_index].revents = 0; + if(context->current_out_packet){ + pollfds[pollfd_index].events |= POLLOUT; + } + context->pollfd_index = pollfd_index; + pollfd_index++; + }else{ + context->bridge->cur_address++; + if(context->bridge->cur_address == context->bridge->address_count){ + context->bridge->cur_address = 0; + } } - context->pollfd_index = pollfd_index; - pollfd_index++; }else{ - context->bridge->cur_address++; - if(context->bridge->cur_address == context->bridge->address_count){ - context->bridge->cur_address = 0; + /* Need to retry */ + if(context->adns->ar_result){ + freeaddrinfo(context->adns->ar_result); } + _mosquitto_free(context->adns); + context->adns = NULL; } }else{ rc = mqtt3_bridge_connect_step1(db, context); From 5eae4b56d6c738aa72da90689d21d013348fb76d Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 7 Feb 2017 16:11:57 +0000 Subject: [PATCH 27/37] [344] More leak fixes. --- lib/net_mosq.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/net_mosq.c b/lib/net_mosq.c index 24174f09..c8776c1a 100644 --- a/lib/net_mosq.c +++ b/lib/net_mosq.c @@ -290,6 +290,8 @@ int _mosquitto_try_connect_step1(struct mosquitto *mosq, const char *host) s = getaddrinfo_a(GAI_NOWAIT, &mosq->adns, 1, sevp); if(s){ errno = s; + _mosquitto_free(mosq->adns); + mosq->adns = NULL; return MOSQ_ERR_EAI; } @@ -343,10 +345,16 @@ int _mosquitto_try_connect_step2(struct mosquitto *mosq, uint16_t port, mosq_soc COMPAT_CLOSE(*sock); *sock = INVALID_SOCKET; } - freeaddrinfo(ainfo); + freeaddrinfo(mosq->adns->ar_result); + mosq->adns->ar_result = NULL; + + _mosquitto_free(mosq->adns); + mosq->adns = NULL; + if(!rp){ return MOSQ_ERR_ERRNO; } + return rc; } From 6f45ab9624c93ac0fe1929dc9f5f440f693bcf54 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 8 Feb 2017 15:40:44 +0000 Subject: [PATCH 28/37] [344] Only do async dns on glibc. --- lib/mosquitto_internal.h | 2 +- lib/net_mosq.c | 2 +- src/bridge.c | 2 +- src/loop.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/mosquitto_internal.h b/lib/mosquitto_internal.h index 640de160..e401a2fb 100644 --- a/lib/mosquitto_internal.h +++ b/lib/mosquitto_internal.h @@ -155,7 +155,7 @@ struct mosquitto { #ifndef WITH_BROKER mosq_sock_t sockpairR, sockpairW; #endif -#ifdef __linux__ +#ifdef __GLIBC__ struct gaicb *adns; /* For getaddrinfo_a */ #endif enum _mosquitto_protocol protocol; diff --git a/lib/net_mosq.c b/lib/net_mosq.c index c8776c1a..c98b2746 100644 --- a/lib/net_mosq.c +++ b/lib/net_mosq.c @@ -271,7 +271,7 @@ static unsigned int psk_client_callback(SSL *ssl, const char *hint, } #endif -#if defined(WITH_BROKER) && defined(__linux__) +#if defined(WITH_BROKER) && defined(__GLIBC__) /* Async connect, part 1 (dns lookup) */ int _mosquitto_try_connect_step1(struct mosquitto *mosq, const char *host) { diff --git a/src/bridge.c b/src/bridge.c index 5f5eb1b3..ad9ef1d8 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -131,7 +131,7 @@ int mqtt3_bridge_new(struct mosquitto_db *db, struct _mqtt3_bridge *bridge) return MOSQ_ERR_NOMEM; } -#ifdef __linux__ +#ifdef __GLIBC__ new_context->bridge->restart_t = 1; /* force quick restart of bridge */ return mqtt3_bridge_connect_step1(db, new_context); #else diff --git a/src/loop.c b/src/loop.c index a4014f0c..dba3c5ea 100644 --- a/src/loop.c +++ b/src/loop.c @@ -247,7 +247,7 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li if((context->bridge->start_type == bst_lazy && context->bridge->lazy_reconnect) || (context->bridge->start_type == bst_automatic && now > context->bridge->restart_t)){ -#ifdef __linux__ +#ifdef __GLIBC__ if(context->adns){ /* Waiting on DNS lookup */ rc = gai_error(context->adns); From 8406c08124a6984053c95b41cceff87878278a32 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 8 Feb 2017 16:24:50 +0000 Subject: [PATCH 29/37] [344] Detect libanl in cmake. --- src/CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9d615636..6918ac26 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -82,6 +82,16 @@ add_executable(mosquitto ${MOSQ_SRCS}) set (MOSQ_LIBS ${MOSQ_LIBS} ${OPENSSL_LIBRARIES}) +# Check for getaddrinfo_a +include(CheckLibraryExists) +check_library_exists(anl getaddrinfo_a "" HAVE_GETADDRINFO_A) +if (HAVE_GETADDRINFO_A) + add_definitions(-DHAVE_GETADDRINFO_A) + set (MOSQ_LIBS ${MOSQ_LIBS} anl) +endif (HAVE_GETADDRINFO_A) + + + if (UNIX) if (APPLE) set (MOSQ_LIBS ${MOSQ_LIBS} dl m) From 433ee5c4d6852b507b43eae9c9a2c9028c6b48e5 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 8 Feb 2017 22:30:00 +0000 Subject: [PATCH 30/37] [344] Don't compile in async dns support by default for makefiles. --- config.mk | 8 ++++++++ lib/mosquitto_internal.h | 2 +- lib/net_mosq.c | 2 +- src/bridge.c | 2 +- src/loop.c | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/config.mk b/config.mk index 3d2aa499..02df80b2 100644 --- a/config.mk +++ b/config.mk @@ -76,6 +76,9 @@ WITH_DOCS:=yes # Build with client support for SOCK5 proxy. WITH_SOCKS:=yes +# Build with async dns lookup support for bridges (temporary). Requires glibc. +#WITH_ADNS:=yes + # ============================================================================= # End of user configuration # ============================================================================= @@ -239,6 +242,11 @@ ifeq ($(WITH_EC),yes) BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_EC endif +ifeq ($(WITH_ADNS),yes) + BROKER_LIBS:=$(BROKER_LIBS) -lanl + BROKER_CFLAGS:=$(BROKER_CFLAGS) -DWITH_ADNS +endif + MAKE_ALL:=mosquitto ifeq ($(WITH_DOCS),yes) MAKE_ALL:=$(MAKE_ALL) docs diff --git a/lib/mosquitto_internal.h b/lib/mosquitto_internal.h index e401a2fb..ac925738 100644 --- a/lib/mosquitto_internal.h +++ b/lib/mosquitto_internal.h @@ -155,7 +155,7 @@ struct mosquitto { #ifndef WITH_BROKER mosq_sock_t sockpairR, sockpairW; #endif -#ifdef __GLIBC__ +#if defined(__GLIBC__) && defined(WITH_ADNS) struct gaicb *adns; /* For getaddrinfo_a */ #endif enum _mosquitto_protocol protocol; diff --git a/lib/net_mosq.c b/lib/net_mosq.c index c98b2746..06c9bce2 100644 --- a/lib/net_mosq.c +++ b/lib/net_mosq.c @@ -271,7 +271,7 @@ static unsigned int psk_client_callback(SSL *ssl, const char *hint, } #endif -#if defined(WITH_BROKER) && defined(__GLIBC__) +#if defined(WITH_BROKER) && defined(__GLIBC__) && defined(WITH_ADNS) /* Async connect, part 1 (dns lookup) */ int _mosquitto_try_connect_step1(struct mosquitto *mosq, const char *host) { diff --git a/src/bridge.c b/src/bridge.c index ad9ef1d8..869b3db1 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -131,7 +131,7 @@ int mqtt3_bridge_new(struct mosquitto_db *db, struct _mqtt3_bridge *bridge) return MOSQ_ERR_NOMEM; } -#ifdef __GLIBC__ +#if defined(__GLIBC__) && defined(WITH_ADNS) new_context->bridge->restart_t = 1; /* force quick restart of bridge */ return mqtt3_bridge_connect_step1(db, new_context); #else diff --git a/src/loop.c b/src/loop.c index dba3c5ea..b7e8b752 100644 --- a/src/loop.c +++ b/src/loop.c @@ -247,7 +247,7 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li if((context->bridge->start_type == bst_lazy && context->bridge->lazy_reconnect) || (context->bridge->start_type == bst_automatic && now > context->bridge->restart_t)){ -#ifdef __GLIBC__ +#if defined(__GLIBC__) && defined(WITH_ADNS) if(context->adns){ /* Waiting on DNS lookup */ rc = gai_error(context->adns); From b55e7035ffcc0f942e77bdcb25750d711a79dfdb Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 9 Feb 2017 16:41:48 +0000 Subject: [PATCH 31/37] [344] Fix non-async case. --- src/bridge.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 107 insertions(+), 4 deletions(-) diff --git a/src/bridge.c b/src/bridge.c index 869b3db1..dc5f9c44 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -139,6 +139,7 @@ int mqtt3_bridge_new(struct mosquitto_db *db, struct _mqtt3_bridge *bridge) #endif } +#if defined(__GLIBC__) && defined(WITH_ADNS) int mqtt3_bridge_connect_step1(struct mosquitto_db *db, struct mosquitto *context) { int rc; @@ -288,17 +289,119 @@ int mqtt3_bridge_connect_step2(struct mosquitto_db *db, struct mosquitto *contex return rc; } } - +#else int mqtt3_bridge_connect(struct mosquitto_db *db, struct mosquitto *context) { int rc; + int i; + char *notification_topic; + int notification_topic_len; + uint8_t notification_payload; + + if(!context || !context->bridge) return MOSQ_ERR_INVAL; + + context->state = mosq_cs_new; + context->sock = INVALID_SOCKET; + context->last_msg_in = mosquitto_time(); + context->next_msg_out = mosquitto_time() + context->bridge->keepalive; + context->keepalive = context->bridge->keepalive; + context->clean_session = context->bridge->clean_session; + context->in_packet.payload = NULL; + context->ping_t = 0; + context->bridge->lazy_reconnect = false; + mqtt3_bridge_packet_cleanup(context); + mqtt3_db_message_reconnect_reset(db, context); + + if(context->clean_session){ + mqtt3_db_messages_delete(db, context); + } + + /* Delete all local subscriptions even for clean_session==false. We don't + * remove any messages and the next loop carries out the resubscription + * anyway. This means any unwanted subs will be removed. + */ + mqtt3_subs_clean_session(db, context); + + for(i=0; ibridge->topic_count; i++){ + if(context->bridge->topics[i].direction == bd_out || context->bridge->topics[i].direction == bd_both){ + _mosquitto_log_printf(NULL, MOSQ_LOG_DEBUG, "Bridge %s doing local SUBSCRIBE on topic %s", context->id, context->bridge->topics[i].local_topic); + if(mqtt3_sub_add(db, context, context->bridge->topics[i].local_topic, context->bridge->topics[i].qos, &db->subs)) return 1; + } + } - rc = mqtt3_bridge_connect_step1(db, context); - if(rc) return rc; + if(context->bridge->notifications){ + if(context->bridge->notification_topic){ + if(!context->bridge->initial_notification_done){ + notification_payload = '0'; + mqtt3_db_messages_easy_queue(db, context, context->bridge->notification_topic, 1, 1, ¬ification_payload, 1); + context->bridge->initial_notification_done = true; + } + notification_payload = '0'; + rc = _mosquitto_will_set(context, context->bridge->notification_topic, 1, ¬ification_payload, 1, true); + if(rc != MOSQ_ERR_SUCCESS){ + return rc; + } + }else{ + notification_topic_len = strlen(context->bridge->remote_clientid)+strlen("$SYS/broker/connection//state"); + notification_topic = _mosquitto_malloc(sizeof(char)*(notification_topic_len+1)); + if(!notification_topic) return MOSQ_ERR_NOMEM; - return mqtt3_bridge_connect_step2(db, context); + snprintf(notification_topic, notification_topic_len+1, "$SYS/broker/connection/%s/state", context->bridge->remote_clientid); + + if(!context->bridge->initial_notification_done){ + notification_payload = '0'; + mqtt3_db_messages_easy_queue(db, context, notification_topic, 1, 1, ¬ification_payload, 1); + context->bridge->initial_notification_done = true; + } + + notification_payload = '0'; + rc = _mosquitto_will_set(context, notification_topic, 1, ¬ification_payload, 1, true); + _mosquitto_free(notification_topic); + if(rc != MOSQ_ERR_SUCCESS){ + return rc; + } + } + } + + _mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "Connecting bridge %s (%s:%d)", context->bridge->name, context->bridge->addresses[context->bridge->cur_address].address, context->bridge->addresses[context->bridge->cur_address].port); + rc = _mosquitto_socket_connect(context, context->bridge->addresses[context->bridge->cur_address].address, context->bridge->addresses[context->bridge->cur_address].port, NULL, false); + if(rc > 0 ){ + if(rc == MOSQ_ERR_TLS){ + _mosquitto_socket_close(db, context); + return rc; /* Error already printed */ + }else if(rc == MOSQ_ERR_ERRNO){ + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error creating bridge: %s.", strerror(errno)); + }else if(rc == MOSQ_ERR_EAI){ + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error creating bridge: %s.", gai_strerror(errno)); + } + + return rc; + } + + HASH_ADD(hh_sock, db->contexts_by_sock, sock, sizeof(context->sock), context); + + if(rc == MOSQ_ERR_CONN_PENDING){ + context->state = mosq_cs_connect_pending; + } + rc = _mosquitto_send_connect(context, context->keepalive, context->clean_session); + if(rc == MOSQ_ERR_SUCCESS){ + return MOSQ_ERR_SUCCESS; + }else if(rc == MOSQ_ERR_ERRNO && errno == ENOTCONN){ + return MOSQ_ERR_SUCCESS; + }else{ + if(rc == MOSQ_ERR_TLS){ + return rc; /* Error already printed */ + }else if(rc == MOSQ_ERR_ERRNO){ + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error creating bridge: %s.", strerror(errno)); + }else if(rc == MOSQ_ERR_EAI){ + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error creating bridge: %s.", gai_strerror(errno)); + } + _mosquitto_socket_close(db, context); + return rc; + } } +#endif void mqtt3_bridge_packet_cleanup(struct mosquitto *context) From 1a0240b5d5c3db14e83e1dfa2c81acad5052def8 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sun, 12 Feb 2017 21:22:58 +0000 Subject: [PATCH 32/37] [379] Improve mosquitto_passwd error messages. Thanks to Jaimyn Mayer. Closes #379. Bug: https://github.com/eclipse/mosquitto/issues/379 --- ChangeLog.txt | 1 + src/mosquitto_passwd.c | 57 ++++++++++++++++++++++++++---------------- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 00dd0704..c03ad2bc 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -6,6 +6,7 @@ Broker: - For http only websockets clients, close files served over http in all cases when the client disconnects. Closes #354. - Fix error message when websockets http_dir directory does not exist. +- Improve password utility error message. Closes #379. Client library: - Clients can now use TLS with IPv6. diff --git a/src/mosquitto_passwd.c b/src/mosquitto_passwd.c index de9a719a..aa7a8101 100644 --- a/src/mosquitto_passwd.c +++ b/src/mosquitto_passwd.c @@ -377,35 +377,50 @@ int main(int argc, char *argv[]) OpenSSL_add_all_digests(); - if(argc == 5){ - if(!strcmp(argv[1], "-b")){ - batch_mode = true; - }else{ - fprintf(stderr, "Error: Unknown option '%s'\n", argv[1]); + if(argc == 1){ + print_usage(); + return 1; + } + + if(!strcmp(argv[1], "-c")){ + create_new = true; + if(argc != 4){ + fprintf(stderr, "Error: -c argument given but password file or username missing.\n"); return 1; + }else{ + password_file_tmp = argv[2]; + username = argv[3]; } - password_file_tmp = argv[2]; - username = argv[3]; - password_cmd = argv[4]; - }else if(argc == 4){ - if(!strcmp(argv[1], "-c")){ - create_new = true; - }else if(!strcmp(argv[1], "-D")){ - delete_user = true; + }else if(!strcmp(argv[1], "-D")){ + delete_user = true; + if(argc != 4){ + fprintf(stderr, "Error: -D argument given but password file or username missing.\n"); + return 1; }else{ - fprintf(stderr, "Error: Unknown option '%s'\n", argv[1]); + password_file_tmp = argv[2]; + username = argv[3]; + } + }else if(!strcmp(argv[1], "-b")){ + batch_mode = true; + if(argc != 5){ + fprintf(stderr, "Error: -b argument given but password file, username or password missing.\n"); return 1; + }else{ + password_file_tmp = argv[2]; + username = argv[3]; + password_cmd = argv[4]; } - password_file_tmp = argv[2]; - username = argv[3]; - }else if(argc == 3){ - if(!strcmp(argv[1], "-U")){ + }else if(!strcmp(argv[1], "-U")){ + if(argc != 3){ + fprintf(stderr, "Error: -U argument given but password file missing.\n"); + return 1; + }else{ do_update_file = true; password_file_tmp = argv[2]; - }else{ - password_file_tmp = argv[1]; - username = argv[2]; } + }else if(argc == 3){ + password_file_tmp = argv[1]; + username = argv[2]; }else{ print_usage(); return 1; From cac5464f7f2843beb0d4dd65b7766b6e5e8c7c23 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 15 Feb 2017 21:01:49 +0000 Subject: [PATCH 33/37] Use of --ciphers no longer requires you to also pass --tls-version. Closes #380. Bug: https://github.com/eclipse/mosquitto/issues/380 --- ChangeLog.txt | 4 ++++ client/client_shared.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index c03ad2bc..c3e05be7 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -8,6 +8,10 @@ Broker: - Fix error message when websockets http_dir directory does not exist. - Improve password utility error message. Closes #379. +Clients: +- Use of --ciphers no longer requires you to also pass --tls-version. + Closes #380. + Client library: - Clients can now use TLS with IPv6. - Fix potential socket leakage when reconnecting. Closes #304. diff --git a/client/client_shared.c b/client/client_shared.c index cecc5ab5..b82d6c24 100644 --- a/client/client_shared.c +++ b/client/client_shared.c @@ -690,7 +690,7 @@ int client_opts_set(struct mosquitto *mosq, struct mosq_config *cfg) return 1; } # endif - if(cfg->tls_version && mosquitto_tls_opts_set(mosq, 1, cfg->tls_version, cfg->ciphers)){ + if((cfg->tls_version || cfg->ciphers) && mosquitto_tls_opts_set(mosq, 1, cfg->tls_version, cfg->ciphers)){ if(!cfg->quiet) fprintf(stderr, "Error: Problem setting TLS options.\n"); mosquitto_lib_cleanup(); return 1; From 92f3d50b8e48598f77e50062e4ed7844209f5e00 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 20 Feb 2017 21:20:00 +0000 Subject: [PATCH 34/37] EPROTO is defined on MSVC 2015. --- config.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/config.h b/config.h index fbe4babb..6af5c283 100644 --- a/config.h +++ b/config.h @@ -13,6 +13,7 @@ * ============================================================ */ #if defined(_MSC_VER) && _MSC_VER < 1900 # define snprintf sprintf_s +# define EPROTO ECONNABORTED #endif #ifdef WIN32 @@ -27,6 +28,3 @@ #define uthash_malloc(sz) _mosquitto_malloc(sz) #define uthash_free(ptr,sz) _mosquitto_free(ptr) -#ifndef EPROTO -# define EPROTO ECONNABORTED -#endif From 9a2987c145b797cfcd1bbcfb506327de13f8f50f Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 20 Feb 2017 21:48:25 +0000 Subject: [PATCH 35/37] Missing malloc check. --- client/client_shared.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client/client_shared.c b/client/client_shared.c index b82d6c24..caa33e18 100644 --- a/client/client_shared.c +++ b/client/client_shared.c @@ -924,6 +924,10 @@ static int mosquitto__parse_socks_url(struct mosq_config *cfg, char *url) port[len] = '\0'; }else{ host = malloc(len + 1); + if(!host){ + fprintf(stderr, "Error: Out of memory.\n"); + goto cleanup; + } memcpy(host, &(str[start]), len); host[len] = '\0'; } From bda989371312780cc544ee246b107d3b42afa669 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 20 Feb 2017 21:57:45 +0000 Subject: [PATCH 36/37] Version bump. --- CMakeLists.txt | 2 +- ChangeLog.txt | 3 +++ config.mk | 2 +- installer/mosquitto-cygwin.nsi | 2 +- installer/mosquitto.nsi | 2 +- lib/mosquitto.h | 2 +- set-version.sh | 2 +- 7 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 29fb4b45..b0f29a2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ project(mosquitto) cmake_minimum_required(VERSION 2.8) # Only for version 3 and up. cmake_policy(SET CMP0042 NEW) -set (VERSION 1.4.10) +set (VERSION 1.4.11) if (WIN32) execute_process(COMMAND cmd /c echo %DATE% %TIME% OUTPUT_VARIABLE TIMESTAMP diff --git a/ChangeLog.txt b/ChangeLog.txt index c3e05be7..57f9ee2c 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,6 @@ +1.4.11 - 20170220 +================= + Broker: - Fix crash when "lazy" type bridge attempts to reconnect. Closes #259. - maximum_connections now applies to websockets listeners. Closes #271. diff --git a/config.mk b/config.mk index 02df80b2..6e369c23 100644 --- a/config.mk +++ b/config.mk @@ -86,7 +86,7 @@ WITH_SOCKS:=yes # Also bump lib/mosquitto.h, CMakeLists.txt, # installer/mosquitto.nsi, installer/mosquitto-cygwin.nsi -VERSION=1.4.10 +VERSION=1.4.11 TIMESTAMP:=$(shell date "+%F %T%z") # Client library SO version. Bump if incompatible API/ABI changes are made. diff --git a/installer/mosquitto-cygwin.nsi b/installer/mosquitto-cygwin.nsi index eea6ae42..1567c73b 100644 --- a/installer/mosquitto-cygwin.nsi +++ b/installer/mosquitto-cygwin.nsi @@ -7,7 +7,7 @@ !define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' Name "mosquitto" -!define VERSION 1.4.10 +!define VERSION 1.4.11 OutFile "mosquitto-${VERSION}-install-cygwin.exe" InstallDir "$PROGRAMFILES\mosquitto" diff --git a/installer/mosquitto.nsi b/installer/mosquitto.nsi index 7dc4d1f8..4afe737b 100644 --- a/installer/mosquitto.nsi +++ b/installer/mosquitto.nsi @@ -9,7 +9,7 @@ !define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' Name "mosquitto" -!define VERSION 1.4.10 +!define VERSION 1.4.11 OutFile "mosquitto-${VERSION}-install-win32.exe" InstallDir "$PROGRAMFILES\mosquitto" diff --git a/lib/mosquitto.h b/lib/mosquitto.h index 2058d59a..43e1f15f 100644 --- a/lib/mosquitto.h +++ b/lib/mosquitto.h @@ -45,7 +45,7 @@ extern "C" { #define LIBMOSQUITTO_MAJOR 1 #define LIBMOSQUITTO_MINOR 4 -#define LIBMOSQUITTO_REVISION 10 +#define LIBMOSQUITTO_REVISION 11 /* LIBMOSQUITTO_VERSION_NUMBER looks like 1002001 for e.g. version 1.2.1. */ #define LIBMOSQUITTO_VERSION_NUMBER (LIBMOSQUITTO_MAJOR*1000000+LIBMOSQUITTO_MINOR*1000+LIBMOSQUITTO_REVISION) diff --git a/set-version.sh b/set-version.sh index 71631010..75c0b529 100755 --- a/set-version.sh +++ b/set-version.sh @@ -2,7 +2,7 @@ MAJOR=1 MINOR=4 -REVISION=9 +REVISION=11 sed -i "s/^VERSION=.*/VERSION=${MAJOR}.${MINOR}.${REVISION}/" config.mk From 81340aa5bb5c46f40ebe4c3b8a1cfbc09e5ee009 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 21 Feb 2017 12:02:02 +0000 Subject: [PATCH 37/37] Add snap support. --- snap/mosquitto.conf | 3 +++ snap/snapcraft.yaml | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 snap/mosquitto.conf create mode 100644 snap/snapcraft.yaml diff --git a/snap/mosquitto.conf b/snap/mosquitto.conf new file mode 100644 index 00000000..43396eb7 --- /dev/null +++ b/snap/mosquitto.conf @@ -0,0 +1,3 @@ +port 1883 +persistence true +user root diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml new file mode 100644 index 00000000..261b9fa7 --- /dev/null +++ b/snap/snapcraft.yaml @@ -0,0 +1,45 @@ +name: mosquitto-simple +version: 1.4.11 +summary: Eclipse Mosquitto MQTT broker +description: This is a message broker that supports version 3.1 and 3.1.1 of the MQTT + protocol. + MQTT provides a method of carrying out messaging using a publish/subscribe + model. It is lightweight, both in terms of bandwidth usage and ease of + implementation. This makes it particularly useful at the edge of the network + where a sensor or other simple device may be implemented using an arduino for + example. +confinement: strict + +apps: + mosquitto: + command: usr/local/sbin/mosquitto -c $SNAP/mosquitto.conf + daemon: simple + restart-condition: always + plugs: [network, network-bind] + + +parts: + script: + plugin: dump + source: snap/ + prime: + - mosquitto.conf + + + mosquitto: + plugin: make + source: https://github.com/eclipse/mosquitto + source-type: git + + build-packages: + - libssl-dev + - uuid-dev + stage-packages: + - libssl1.0.0 + - libuuid1 + prime: + - usr/local/sbin/mosquitto + - lib/*-linux-gnu/libcrypto.so* + - lib/*-linux-gnu/libssl.so* + - lib/*-linux-gnu/libuuid.so* +