From c02cdbefdc82dc36ed0a042c1e49cde359754e7f Mon Sep 17 00:00:00 2001 From: Simon Wunderlich Date: Wed, 4 Feb 2015 19:38:30 +0100 Subject: [PATCH 01/14] mosquitto-lib: close socketpair on (re)connect If the socket pair is still opened on reconnect, close it before creating it again (just like the state variables). Otherwise, these sockets are leaked on multiple mosquitto_connect() calls. Signed-off-by: Simon Wunderlich --- lib/mosquitto.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/mosquitto.c b/lib/mosquitto.c index 50ba9eb6..195a25aa 100644 --- a/lib/mosquitto.c +++ b/lib/mosquitto.c @@ -407,6 +407,15 @@ static int _mosquitto_connect_init(struct mosquitto *mosq, const char *host, int mosq->keepalive = keepalive; + if(mosq->sockpairR != INVALID_SOCKET){ + COMPAT_CLOSE(mosq->sockpairR); + mosq->sockpairR = INVALID_SOCKET; + } + if(mosq->sockpairW != INVALID_SOCKET){ + COMPAT_CLOSE(mosq->sockpairW); + mosq->sockpairW = INVALID_SOCKET; + } + if(_mosquitto_socketpair(&mosq->sockpairR, &mosq->sockpairW)){ _mosquitto_log_printf(mosq, MOSQ_LOG_WARNING, "Warning: Unable to open socket pair, outgoing publish commands may be delayed."); From 89763a51d95e579f0e5d852e2d34a50adababa5d Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sun, 11 Oct 2015 22:55:54 +0100 Subject: [PATCH 02/14] [478917] Don't truncate lines with "mosquitto_pub -l" Thanks to Jan-Piet Mens. Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=478917 --- ChangeLog.txt | 3 +++ client/pub_client.c | 43 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 0d083a5e..93a3ab58 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,6 @@ +Clients: +- "mosquitto_pub -l" now no longer limited to 1024 byte lines. Closes #478917. + 1.4.4 - 20150916 ================ diff --git a/client/pub_client.c b/client/pub_client.c index b29dd60e..5fc27ca0 100644 --- a/client/pub_client.c +++ b/client/pub_client.c @@ -290,11 +290,22 @@ void print_usage(void) int main(int argc, char *argv[]) { struct mosq_config cfg; - char buf[1024]; struct mosquitto *mosq = NULL; int rc; int rc2; + char *buf; + int buf_len = 1024; + int buf_len_actual; + int read_len; + int pos; + buf = malloc(buf_len); + if(!buf){ + fprintf(stderr, "Error: Out of memory.\n"); + return 1; + } + + memset(&cfg, 0, sizeof(struct mosq_config)); rc = client_config_load(&cfg, CLIENT_PUB, argc, argv); if(rc){ client_config_cleanup(&cfg); @@ -375,14 +386,30 @@ int main(int argc, char *argv[]) do{ if(mode == MSGMODE_STDIN_LINE){ if(status == STATUS_CONNACK_RECVD){ - if(fgets(buf, 1024, stdin)){ - buf[strlen(buf)-1] = '\0'; - rc2 = mosquitto_publish(mosq, &mid_sent, topic, strlen(buf), buf, qos, retain); - if(rc2){ - if(!quiet) fprintf(stderr, "Error: Publish returned %d, disconnecting.\n", rc2); - mosquitto_disconnect(mosq); + pos = 0; + read_len = buf_len; + while(fgets(&buf[pos], read_len, stdin)){ + buf_len_actual = strlen(buf); + if(buf[buf_len_actual-1] == '\n'){ + buf[buf_len_actual-1] = '\0'; + rc2 = mosquitto_publish(mosq, &mid_sent, topic, buf_len_actual, buf, qos, retain); + if(rc2){ + if(!quiet) fprintf(stderr, "Error: Publish returned %d, disconnecting.\n", rc2); + mosquitto_disconnect(mosq); + } + break; + }else{ + buf_len += 1024; + pos += 1023; + read_len = 1024; + buf = realloc(buf, buf_len); + if(!buf){ + fprintf(stderr, "Error: Out of memory.\n"); + return 1; + } } - }else if(feof(stdin)){ + } + if(feof(stdin)){ last_mid = mid_sent; status = STATUS_WAITING; } From 26eac3c1ca900db83a05ec9305e01c218f4ff725 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 12 Oct 2015 14:48:52 +0100 Subject: [PATCH 03/14] Fix possible memory leak with bridges and SSL. Fix possible memory leak if bridge using SSL attempts to connect to a host that is not up. Thanks to Ed Morris. --- ChangeLog.txt | 4 ++++ src/bridge.c | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 93a3ab58..3675fbe8 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,7 @@ +Broker: +- Fix possible memory leak if bridge using SSL attempts to connect to a + host that is not up. + Clients: - "mosquitto_pub -l" now no longer limited to 1024 byte lines. Closes #478917. diff --git a/src/bridge.c b/src/bridge.c index 9f7263cc..c4faf26a 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -211,6 +211,7 @@ int mqtt3_bridge_connect(struct mosquitto_db *db, struct mosquitto *context) 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)); From 422a156e9823f22269d4df15c5bfe358e61e7acc Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 15 Oct 2015 16:13:44 +0100 Subject: [PATCH 04/14] Revert man page to html rather than php. --- man/Makefile | 2 +- man/html.xsl | 22 ---------------------- man/libmosquitto.3.xml | 4 ++-- man/mosquitto-tls.7.xml | 4 ++-- man/mosquitto.8.xml | 16 ++++++++-------- man/mosquitto.conf.5.xml | 8 ++++---- man/mosquitto_passwd.1.xml | 6 +++--- man/mosquitto_pub.1.xml | 10 +++++----- man/mosquitto_sub.1.xml | 10 +++++----- man/mqtt.7.xml | 6 +++--- 10 files changed, 33 insertions(+), 55 deletions(-) diff --git a/man/Makefile b/man/Makefile index daacab99..a0496869 100644 --- a/man/Makefile +++ b/man/Makefile @@ -64,7 +64,7 @@ html : *.xml set -e; for m in *.xml; \ do \ hfile=$$(echo $${m} | sed -e 's#\(.*\)\.xml#\1#' | sed -e 's/\./-/g'); \ - $(XSLTPROC) html.xsl $${m} > $${hfile}.php; \ + $(XSLTPROC) html.xsl $${m} > $${hfile}.html; \ done potgen : diff --git a/man/html.xsl b/man/html.xsl index d7f9001f..44f00187 100644 --- a/man/html.xsl +++ b/man/html.xsl @@ -9,26 +9,4 @@ - - - - - - - - - ]]> - - - - - - - - - ]]> - - - - diff --git a/man/libmosquitto.3.xml b/man/libmosquitto.3.xml index 6a04888c..528b6beb 100644 --- a/man/libmosquitto.3.xml +++ b/man/libmosquitto.3.xml @@ -457,11 +457,11 @@ int main(int argc, char *argv[]) - mosquitto + mosquitto 8 - mqtt + mqtt 7 diff --git a/man/mosquitto-tls.7.xml b/man/mosquitto-tls.7.xml index ddb02aa8..1fa40f7f 100644 --- a/man/mosquitto-tls.7.xml +++ b/man/mosquitto-tls.7.xml @@ -80,13 +80,13 @@ - mosquitto + mosquitto 8 - mosquitto-conf + mosquitto-conf 5 diff --git a/man/mosquitto.8.xml b/man/mosquitto.8.xml index fb87ab70..40242784 100644 --- a/man/mosquitto.8.xml +++ b/man/mosquitto.8.xml @@ -481,49 +481,49 @@ - mqtt + mqtt 7 - mosquitto-tls + mosquitto-tls 7 - mosquitto.conf + mosquitto.conf 5 - hosts_access + hosts_access 5 - mosquitto_passwd + mosquitto_passwd 1 - mosquitto_pub + mosquitto_pub 1 - mosquitto_sub + mosquitto_sub 1 - libmosquitto + libmosquitto 3 diff --git a/man/mosquitto.conf.5.xml b/man/mosquitto.conf.5.xml index 59b4c8e7..e27fb589 100644 --- a/man/mosquitto.conf.5.xml +++ b/man/mosquitto.conf.5.xml @@ -1399,25 +1399,25 @@ topic clients/total in 0 test/mosquitto/org $SYS/broker/ - mosquitto + mosquitto 8 - mosquitto_passwd + mosquitto_passwd 1 - mosquitto-tls + mosquitto-tls 7 - mqtt + mqtt 7 diff --git a/man/mosquitto_passwd.1.xml b/man/mosquitto_passwd.1.xml index 88324e75..6a75b8d4 100644 --- a/man/mosquitto_passwd.1.xml +++ b/man/mosquitto_passwd.1.xml @@ -132,19 +132,19 @@ - mosquitto + mosquitto 8 - mosquitto.conf + mosquitto.conf 5 - mqtt + mqtt 7 diff --git a/man/mosquitto_pub.1.xml b/man/mosquitto_pub.1.xml index 171415c9..69e12b92 100644 --- a/man/mosquitto_pub.1.xml +++ b/man/mosquitto_pub.1.xml @@ -483,31 +483,31 @@ - mqtt + mqtt 7 - mosquitto_sub + mosquitto_sub 1 - mosquitto + mosquitto 8 - libmosquitto + libmosquitto 3 - mosquitto-tls + mosquitto-tls 7 diff --git a/man/mosquitto_sub.1.xml b/man/mosquitto_sub.1.xml index 7e6f6428..93524b3e 100644 --- a/man/mosquitto_sub.1.xml +++ b/man/mosquitto_sub.1.xml @@ -517,31 +517,31 @@ - mqtt + mqtt 7 - mosquitto_pub + mosquitto_pub 1 - mosquitto + mosquitto 8 - libmosquitto + libmosquitto 3 - mosquitto-tls + mosquitto-tls 7 diff --git a/man/mqtt.7.xml b/man/mqtt.7.xml index eebc85c0..d467fce9 100644 --- a/man/mqtt.7.xml +++ b/man/mqtt.7.xml @@ -161,19 +161,19 @@ - mosquitto + mosquitto 8 - mosquitto_pub + mosquitto_pub 1 - mosquitto_sub + mosquitto_sub 1 From 6531a0f49d4f8525ff6d39b506542e4d02f9a36b Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sun, 1 Nov 2015 16:39:40 +0000 Subject: [PATCH 05/14] Contributing note. --- CONTRIBUTING.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b4b2bf5b..c3b76c99 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -47,6 +47,10 @@ There are further details at - +If your contribution is a fix for a bug, please use the 'fixes' branch as the +base for your work. If you are proposing new behaviour/features please use the +'develop' branch. + Once the patch is pushed back to Gerrit, the project committers will be informed and they will undertake a review of the code. The patch may need modifying for some reason. In order to make amending commits more From 80300f8fa1b6b758e171594fd3092f7f7996f69c Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sun, 8 Nov 2015 20:23:07 +0000 Subject: [PATCH 06/14] [468987] Free unused topic tree elements. Fix in 1.4.3 was incomplete. Thanks to Guido Hinderberger et al. --- ChangeLog.txt | 3 +++ src/subs.c | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 3675fbe8..9b38c7c2 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,10 +1,13 @@ Broker: - Fix possible memory leak if bridge using SSL attempts to connect to a host that is not up. +- Free unused topic tree elements (fix in 1.4.3 was incomplete). Closes + #468987. Clients: - "mosquitto_pub -l" now no longer limited to 1024 byte lines. Closes #478917. + 1.4.4 - 20150916 ================ diff --git a/src/subs.c b/src/subs.c index 1d46231f..4f64b3e5 100644 --- a/src/subs.c +++ b/src/subs.c @@ -553,20 +553,22 @@ static struct _mosquitto_subhier *tmp_remove_subs(struct _mosquitto_subhier *sub if(!sub || !sub->parent){ return NULL; } - if(sub->children || sub->subs || sub->next){ + + if(sub->children || sub->subs){ return NULL; } parent = sub->parent; hier = sub->parent->children; + while(hier){ if(hier == sub){ if(last){ - last->next = sub->next; + last->next = hier->next; }else{ - parent->children = NULL; + parent->children = hier->next; } - if(sub->topic) _mosquitto_free(sub->topic); + _mosquitto_free(sub->topic); _mosquitto_free(sub); break; } From 3cab5e2e69f3d650f9d8e261be42ac906359ed83 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sun, 8 Nov 2015 21:25:04 +0000 Subject: [PATCH 07/14] Bump version number. --- CMakeLists.txt | 2 +- ChangeLog.txt | 3 +++ config.mk | 2 +- installer/mosquitto-cygwin.nsi | 2 +- installer/mosquitto.nsi | 2 +- lib/mosquitto.h | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d151a814..380299f4 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.4) +set (VERSION 1.4.5) if (WIN32) execute_process(COMMAND cmd /c echo %DATE% %TIME% OUTPUT_VARIABLE TIMESTAMP diff --git a/ChangeLog.txt b/ChangeLog.txt index 9b38c7c2..a50c070e 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,6 @@ +1.4.5 - 20151108 +================ + Broker: - Fix possible memory leak if bridge using SSL attempts to connect to a host that is not up. diff --git a/config.mk b/config.mk index 33e206c9..94c31521 100644 --- a/config.mk +++ b/config.mk @@ -83,7 +83,7 @@ WITH_SOCKS:=yes # Also bump lib/mosquitto.h, CMakeLists.txt, # installer/mosquitto.nsi, installer/mosquitto-cygwin.nsi -VERSION=1.4.4 +VERSION=1.4.5 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 6fcfc34d..eb646d41 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.4 +!define VERSION 1.4.5 OutFile "mosquitto-${VERSION}-install-cygwin.exe" InstallDir "$PROGRAMFILES\mosquitto" diff --git a/installer/mosquitto.nsi b/installer/mosquitto.nsi index f6f5b7a3..236a3e66 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.4 +!define VERSION 1.4.5 OutFile "mosquitto-${VERSION}-install-win32.exe" InstallDir "$PROGRAMFILES\mosquitto" diff --git a/lib/mosquitto.h b/lib/mosquitto.h index f84dd630..9176910e 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 4 +#define LIBMOSQUITTO_REVISION 5 /* 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) From f58f8aac0f9ef23cc6999e52d1e1ba9cdf8adeaa Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 16 Nov 2015 16:47:12 +0000 Subject: [PATCH 08/14] Document updates. --- lib/mosquitto.h | 1 + man/libmosquitto.3.xml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/mosquitto.h b/lib/mosquitto.h index 9176910e..b6d94372 100644 --- a/lib/mosquitto.h +++ b/lib/mosquitto.h @@ -576,6 +576,7 @@ libmosq_EXPORT int mosquitto_disconnect(struct mosquitto *mosq); * Note that although the MQTT protocol doesn't use message ids * for messages with QoS=0, libmosquitto assigns them message ids * so they can be tracked with this parameter. + * topic - null terminated string of the topic to publish to. * payloadlen - the size of the payload (bytes). Valid values are between 0 and * 268,435,455. * payload - pointer to the data to send. If payloadlen > 0 this must be a diff --git a/man/libmosquitto.3.xml b/man/libmosquitto.3.xml index 528b6beb..0ceaf05b 100644 --- a/man/libmosquitto.3.xml +++ b/man/libmosquitto.3.xml @@ -444,8 +444,8 @@ int main(int argc, char *argv[]) return 1; } - while(!mosquitto_loop(mosq, -1, 1)){ - } + mosquitto_loop_forever(mosq, -1, 1); + mosquitto_destroy(mosq); mosquitto_lib_cleanup(); return 0; From 148df821446345c2752cbbca09d702a751ee0add Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Fri, 18 Dec 2015 21:58:38 +0000 Subject: [PATCH 09/14] [484693] Fix _mosquitto_socketpair() on Windows. Thanks to Steve Woods and Roman Bogus. Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=484693 Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=479143 --- ChangeLog.txt | 8 ++++++++ lib/net_mosq.c | 6 ++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index a50c070e..9c6c5e6b 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,11 @@ +1.4.6 - +================ + +Client library: +- Fix _mosquitto_socketpair() on Windows, reducing the chance of delays when + publishing. Closes #484693. + + 1.4.5 - 20151108 ================ diff --git a/lib/net_mosq.c b/lib/net_mosq.c index 0117ea10..4c258a47 100644 --- a/lib/net_mosq.c +++ b/lib/net_mosq.c @@ -1125,10 +1125,6 @@ int _mosquitto_socketpair(mosq_sock_t *pairR, mosq_sock_t *pairW) continue; } - if(_mosquitto_socket_nonblock(listensock)){ - continue; - } - if(family[i] == AF_INET){ sa->sin_family = family[i]; sa->sin_addr.s_addr = htonl(INADDR_LOOPBACK); @@ -1145,6 +1141,7 @@ int _mosquitto_socketpair(mosq_sock_t *pairR, mosq_sock_t *pairW) continue; } if(_mosquitto_socket_nonblock(spR)){ + COMPAT_CLOSE(spR); COMPAT_CLOSE(listensock); continue; } @@ -1172,6 +1169,7 @@ int _mosquitto_socketpair(mosq_sock_t *pairR, mosq_sock_t *pairW) if(_mosquitto_socket_nonblock(spW)){ COMPAT_CLOSE(spR); + COMPAT_CLOSE(spW); COMPAT_CLOSE(listensock); continue; } From c5a376489ea437e75b79b9c35d45fa240db8fc92 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Fri, 18 Dec 2015 22:26:01 +0000 Subject: [PATCH 10/14] [483979] Fix "mosquitto_pub -l" stripping the final character on a line. Thanks to Allan Kobelansky. Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=483979 --- ChangeLog.txt | 5 ++++- client/pub_client.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 9c6c5e6b..5f299bf2 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -3,8 +3,11 @@ Client library: - Fix _mosquitto_socketpair() on Windows, reducing the chance of delays when - publishing. Closes #484693. + publishing. Closes #483979. +Clients: +- Fix "mosquitto_pub -l" stripping the final character on a line. Closes + #483981. 1.4.5 - 20151108 ================ diff --git a/client/pub_client.c b/client/pub_client.c index 5fc27ca0..c8ca981a 100644 --- a/client/pub_client.c +++ b/client/pub_client.c @@ -392,7 +392,7 @@ int main(int argc, char *argv[]) buf_len_actual = strlen(buf); if(buf[buf_len_actual-1] == '\n'){ buf[buf_len_actual-1] = '\0'; - rc2 = mosquitto_publish(mosq, &mid_sent, topic, buf_len_actual, buf, qos, retain); + rc2 = mosquitto_publish(mosq, &mid_sent, topic, buf_len_actual-1, buf, qos, retain); if(rc2){ if(!quiet) fprintf(stderr, "Error: Publish returned %d, disconnecting.\n", rc2); mosquitto_disconnect(mosq); From 7aa653c42f931867259028eaece56382a2e9a002 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sat, 19 Dec 2015 01:21:17 +0000 Subject: [PATCH 11/14] Add support for libwebsockets 1.6. --- ChangeLog.txt | 4 ++++ lib/mosquitto_internal.h | 4 ++++ lib/net_mosq.c | 1 + src/loop.c | 1 + src/mosquitto.c | 1 + src/mosquitto_broker.h | 24 ++++++++++++++++++++++++ src/read_handle_server.c | 3 ++- src/websockets.c | 34 ++++++++++++++++++++++++++++++++++ 8 files changed, 71 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 5f299bf2..10e312fc 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,9 @@ 1.4.6 - ================ +Broker: +- Add support for libwebsockets 1.6. + Client library: - Fix _mosquitto_socketpair() on Windows, reducing the chance of delays when publishing. Closes #483979. @@ -9,6 +12,7 @@ Clients: - Fix "mosquitto_pub -l" stripping the final character on a line. Closes #483981. + 1.4.5 - 20151108 ================ diff --git a/lib/mosquitto_internal.h b/lib/mosquitto_internal.h index 75d5b2ee..da369168 100644 --- a/lib/mosquitto_internal.h +++ b/lib/mosquitto_internal.h @@ -207,8 +207,12 @@ struct mosquitto { int sub_count; int pollfd_index; # ifdef WITH_WEBSOCKETS +# if defined(LWS_LIBRARY_VERSION_NUMBER) + struct lws *wsi; +# else struct libwebsocket_context *ws_context; struct libwebsocket *wsi; +# endif # endif #else # ifdef WITH_SOCKS diff --git a/lib/net_mosq.c b/lib/net_mosq.c index 4c258a47..a2db4b10 100644 --- a/lib/net_mosq.c +++ b/lib/net_mosq.c @@ -68,6 +68,7 @@ Contributors: extern unsigned long g_pub_msgs_sent; # endif # ifdef WITH_WEBSOCKETS +# include # include # endif #else diff --git a/src/loop.c b/src/loop.c index a5f624b3..b3af85e1 100644 --- a/src/loop.c +++ b/src/loop.c @@ -37,6 +37,7 @@ Contributors: #include #ifdef WITH_WEBSOCKETS +# include # include #endif diff --git a/src/mosquitto.c b/src/mosquitto.c index eaf43953..0bedfd34 100644 --- a/src/mosquitto.c +++ b/src/mosquitto.c @@ -43,6 +43,7 @@ Contributors: #include #endif #ifdef WITH_WEBSOCKETS +# include # include #endif diff --git a/src/mosquitto_broker.h b/src/mosquitto_broker.h index 19498a0b..7e4e6549 100644 --- a/src/mosquitto_broker.h +++ b/src/mosquitto_broker.h @@ -20,6 +20,26 @@ Contributors: #include #include +#ifdef WITH_WEBSOCKETS +# include +# include + +# if defined(LWS_LIBRARY_VERSION_NUMBER) +# define libwebsocket_callback_on_writable(A, B) lws_callback_on_writable((B)) +# define libwebsocket_service(A, B) lws_service((A), (B)) +# define libwebsocket_create_context(A) lws_create_context((A)) +# define libwebsocket_context_destroy(A) lws_context_destroy((A)) +# 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_context lws_context +# define libwebsocket_protocols lws_protocols +# define libwebsocket_callback_reasons lws_callback_reasons +# define libwebsocket lws +# endif +#endif + #include #include #include @@ -482,7 +502,11 @@ void service_run(void); * Websockets related functions * ============================================================ */ #ifdef WITH_WEBSOCKETS +# if defined(LWS_LIBRARY_VERSION_NUMBER) +struct lws_context *mosq_websockets_init(struct _mqtt3_listener *listener, int log_level); +# else struct libwebsocket_context *mosq_websockets_init(struct _mqtt3_listener *listener, int log_level); +# endif #endif void do_disconnect(struct mosquitto_db *db, struct mosquitto *context); diff --git a/src/read_handle_server.c b/src/read_handle_server.c index 973d9aaa..8b0df1be 100644 --- a/src/read_handle_server.c +++ b/src/read_handle_server.c @@ -32,7 +32,8 @@ Contributors: #endif #ifdef WITH_WEBSOCKETS -#include +# include +# include #endif #ifdef WITH_SYS_TREE diff --git a/src/websockets.c b/src/websockets.c index a1f61e89..2c6f2c81 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -29,6 +29,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifdef WITH_WEBSOCKETS +#include #include #include "mosquitto_internal.h" #include "mosquitto_broker.h" @@ -49,13 +50,22 @@ extern unsigned long g_pub_msgs_sent; #endif extern struct mosquitto_db int_db; +#if defined(LWS_LIBRARY_VERSION_NUMBER) +static int callback_mqtt( +#else static int callback_mqtt(struct libwebsocket_context *context, +#endif struct libwebsocket *wsi, enum libwebsocket_callback_reasons reason, void *user, void *in, size_t len); + +#if defined(LWS_LIBRARY_VERSION_NUMBER) +static int callback_http( +#else static int callback_http(struct libwebsocket_context *context, +#endif struct libwebsocket *wsi, enum libwebsocket_callback_reasons reason, void *user, @@ -95,7 +105,9 @@ static struct libwebsocket_protocols protocols[] = { 0, #endif NULL, +#if !defined(LWS_LIBRARY_VERSION_NUMBER) 0 +#endif }, { "mqtt", @@ -106,7 +118,9 @@ static struct libwebsocket_protocols protocols[] = { 1, #endif NULL, +#if !defined(LWS_LIBRARY_VERSION_NUMBER) 0 +#endif }, { "mqttv3.1", @@ -117,10 +131,16 @@ static struct libwebsocket_protocols protocols[] = { 1, #endif NULL, +#if !defined(LWS_LIBRARY_VERSION_NUMBER) 0 +#endif }, #ifdef LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD +# if defined(LWS_LIBRARY_VERSION_NUMBER) + { NULL, NULL, 0, 0, 0, NULL} +# else { NULL, NULL, 0, 0, 0, NULL, 0} +# endif #else { NULL, NULL, 0, 0, NULL, 0} #endif @@ -135,7 +155,11 @@ static void easy_address(int sock, struct mosquitto *mosq) } } +#if defined(LWS_LIBRARY_VERSION_NUMBER) +static int callback_mqtt( +#else static int callback_mqtt(struct libwebsocket_context *context, +#endif struct libwebsocket *wsi, enum libwebsocket_callback_reasons reason, void *user, @@ -158,7 +182,9 @@ static int callback_mqtt(struct libwebsocket_context *context, case LWS_CALLBACK_ESTABLISHED: mosq = mqtt3_context_init(db, WEBSOCKET_CLIENT); if(mosq){ +#if !defined(LWS_LIBRARY_VERSION_NUMBER) mosq->ws_context = context; +#endif mosq->wsi = wsi; u->mosq = mosq; }else{ @@ -342,7 +368,11 @@ static int callback_mqtt(struct libwebsocket_context *context, } +#if defined(LWS_LIBRARY_VERSION_NUMBER) +static int callback_http( +#else static int callback_http(struct libwebsocket_context *context, +#endif struct libwebsocket *wsi, enum libwebsocket_callback_reasons reason, void *user, @@ -368,7 +398,11 @@ static int callback_http(struct libwebsocket_context *context, return -1; } +#if defined(LWS_LIBRARY_VERSION_NUMBER) + hack = (struct libws_mqtt_hack *)lws_context_user(lws_get_context(wsi)); +#else hack = (struct libws_mqtt_hack *)libwebsocket_context_user(context); +#endif if(!hack){ return -1; } From dc02e37af95dc0bfa794d26a63e269138f12d122 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sun, 20 Dec 2015 20:34:22 +0000 Subject: [PATCH 12/14] Bump version number. --- CMakeLists.txt | 2 +- ChangeLog.txt | 2 +- config.mk | 2 +- installer/mosquitto-cygwin.nsi | 2 +- installer/mosquitto.nsi | 2 +- lib/mosquitto.h | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 380299f4..e52539c4 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.5) +set (VERSION 1.4.6) if (WIN32) execute_process(COMMAND cmd /c echo %DATE% %TIME% OUTPUT_VARIABLE TIMESTAMP diff --git a/ChangeLog.txt b/ChangeLog.txt index 10e312fc..b09168fc 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,4 +1,4 @@ -1.4.6 - +1.4.6 - 20151220 ================ Broker: diff --git a/config.mk b/config.mk index 94c31521..b89932c4 100644 --- a/config.mk +++ b/config.mk @@ -83,7 +83,7 @@ WITH_SOCKS:=yes # Also bump lib/mosquitto.h, CMakeLists.txt, # installer/mosquitto.nsi, installer/mosquitto-cygwin.nsi -VERSION=1.4.5 +VERSION=1.4.6 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 eb646d41..46575550 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.5 +!define VERSION 1.4.6 OutFile "mosquitto-${VERSION}-install-cygwin.exe" InstallDir "$PROGRAMFILES\mosquitto" diff --git a/installer/mosquitto.nsi b/installer/mosquitto.nsi index 236a3e66..d514c925 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.5 +!define VERSION 1.4.6 OutFile "mosquitto-${VERSION}-install-win32.exe" InstallDir "$PROGRAMFILES\mosquitto" diff --git a/lib/mosquitto.h b/lib/mosquitto.h index b6d94372..234d407a 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 5 +#define LIBMOSQUITTO_REVISION 6 /* 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) From 25499194132b10153ae357aa5b271d000a5429f3 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 21 Dec 2015 10:53:47 +0000 Subject: [PATCH 13/14] Fix support for libwebsockets 1.22. --- ChangeLog.txt | 7 +++++++ lib/net_mosq.c | 1 - src/loop.c | 1 - src/mosquitto.c | 1 - src/mosquitto_broker.h | 1 - src/read_handle_server.c | 1 - src/websockets.c | 1 - 7 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index b09168fc..2612b520 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,10 @@ +1.4.7 - 20151221 +================ + +Broker: +- Fix support for libwebsockets 1.22. + + 1.4.6 - 20151220 ================ diff --git a/lib/net_mosq.c b/lib/net_mosq.c index a2db4b10..4c258a47 100644 --- a/lib/net_mosq.c +++ b/lib/net_mosq.c @@ -68,7 +68,6 @@ Contributors: extern unsigned long g_pub_msgs_sent; # endif # ifdef WITH_WEBSOCKETS -# include # include # endif #else diff --git a/src/loop.c b/src/loop.c index b3af85e1..a5f624b3 100644 --- a/src/loop.c +++ b/src/loop.c @@ -37,7 +37,6 @@ Contributors: #include #ifdef WITH_WEBSOCKETS -# include # include #endif diff --git a/src/mosquitto.c b/src/mosquitto.c index 0bedfd34..eaf43953 100644 --- a/src/mosquitto.c +++ b/src/mosquitto.c @@ -43,7 +43,6 @@ Contributors: #include #endif #ifdef WITH_WEBSOCKETS -# include # include #endif diff --git a/src/mosquitto_broker.h b/src/mosquitto_broker.h index 7e4e6549..8d197901 100644 --- a/src/mosquitto_broker.h +++ b/src/mosquitto_broker.h @@ -21,7 +21,6 @@ Contributors: #include #ifdef WITH_WEBSOCKETS -# include # include # if defined(LWS_LIBRARY_VERSION_NUMBER) diff --git a/src/read_handle_server.c b/src/read_handle_server.c index 8b0df1be..2e35aaa3 100644 --- a/src/read_handle_server.c +++ b/src/read_handle_server.c @@ -32,7 +32,6 @@ Contributors: #endif #ifdef WITH_WEBSOCKETS -# include # include #endif diff --git a/src/websockets.c b/src/websockets.c index 2c6f2c81..6e641af2 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -29,7 +29,6 @@ POSSIBILITY OF SUCH DAMAGE. #ifdef WITH_WEBSOCKETS -#include #include #include "mosquitto_internal.h" #include "mosquitto_broker.h" From a7136b3672e65df546cbd38a59742f558a108b01 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 21 Dec 2015 11:32:41 +0000 Subject: [PATCH 14/14] Bump version number. --- CMakeLists.txt | 2 +- config.mk | 2 +- installer/mosquitto-cygwin.nsi | 2 +- installer/mosquitto.nsi | 2 +- lib/mosquitto.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e52539c4..086d9179 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.6) +set (VERSION 1.4.7) if (WIN32) execute_process(COMMAND cmd /c echo %DATE% %TIME% OUTPUT_VARIABLE TIMESTAMP diff --git a/config.mk b/config.mk index b89932c4..01532c3c 100644 --- a/config.mk +++ b/config.mk @@ -83,7 +83,7 @@ WITH_SOCKS:=yes # Also bump lib/mosquitto.h, CMakeLists.txt, # installer/mosquitto.nsi, installer/mosquitto-cygwin.nsi -VERSION=1.4.6 +VERSION=1.4.7 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 46575550..f87fca57 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.6 +!define VERSION 1.4.7 OutFile "mosquitto-${VERSION}-install-cygwin.exe" InstallDir "$PROGRAMFILES\mosquitto" diff --git a/installer/mosquitto.nsi b/installer/mosquitto.nsi index d514c925..9e01367e 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.6 +!define VERSION 1.4.7 OutFile "mosquitto-${VERSION}-install-win32.exe" InstallDir "$PROGRAMFILES\mosquitto" diff --git a/lib/mosquitto.h b/lib/mosquitto.h index 234d407a..d279f063 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 6 +#define LIBMOSQUITTO_REVISION 7 /* 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)