Skip to content

Commit

Permalink
Merge branch 'fixes' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ralight committed Feb 13, 2018
2 parents 9750d17 + 15486f4 commit 81cb7ab
Show file tree
Hide file tree
Showing 25 changed files with 582 additions and 141 deletions.
43 changes: 33 additions & 10 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
1.5 - 2017xxxx
1.5 - 2018xxxx
==============

Broker:
Expand Down Expand Up @@ -45,10 +45,25 @@ Broker:
- Remove all build timestamp information including $SYS/broker/timestamp.
Close #651.
- Correctly handle incoming strings that contain a NULL byte. Closes #693.
- Use constant time memcmp for password comparisons.
- Fix incorrect PSK key being used if it had leading zeroes.
- Fix memory leak if a client provided a username/password for a listener with
use_identity_as_username configured.
- Fix use_identity_as_username not working on websockets clients.
- Don't crash if an auth plugin returns MOSQ_ERR_AUTH for a username check on
a websockets client. Closes #490.
- Fix 08-ssl-bridge.py test when using async dns lookups. Closes #507.
- Lines in the config file are no longer limited to 1024 characters long.
Closes #652.
- Fix $SYS counters of messages and bytes sent when message is sent over
a Websockets. Closes #250.
- Fix upgrade_outgoing_qos for retained message. Closes #534.
- Fix CONNACK message not being sent for unauthorised connect on websockets.
Closes #8.

Client library:
- Outgoing messages with QoS>1 are no longer retried after a timeout period.
Messages will be retried when a client reconnects.
Messages will be retried when a client reconnects.
- DNS-SRV support is now disabled by default.
- Add mosquitto_subscribe_simple() This is a helper function to make
retrieving messages from a broker very straightforward. Examples of its use
Expand All @@ -66,21 +81,29 @@ Client library:
- Add mosquitto_pub_topic_check2(), mosquitto_sub_topic_check2(), and
mosquitto_topic_matches_sub2() which are identical to the similarly named
functions but also take length arguments.
- Fix incorrect PSK key being used if it had leading zeroes.
- Initialise "result" variable as soon as possible in
mosquitto_topic_matches_sub. Closes #654.
- No need to close socket again if setting non-blocking failed. Closes #649.
- Fix mosquitto_topic_matches_sub() not correctly matching foo/bar against
foo/+/#. Closes #670.

Client:
Clients:
- Add -F to mosquitto_sub to allow the user to choose the output format.
- Add -U to mosquitto_sub for unsubscribing from topics.
- Add -c (clean session) to mosquitto_pub.
- Add --retained-only to mosquitto_sub to exit after receiving all retained
messages.
- Connections now default to using MQTT v3.1.1.
- Default to using port 8883 when using TLS.
- Correctly handle empty files with "mosquitto_pub -l". Closes #676.

Build:
- Add WITH_STRIP option (defaulting to "no") that when set to "yes" will strip
executables and shared libraries when installing.
- Add WITH_STATIC_LIBRARIES (defaulting to "no") that when set to "yes" will
build and install static versions of the client libraries.
- Don't run TLS-PSK tests if TLS-PSK disabled at compile time. Closes #636.


1.4.14 - 20170710
Expand Down Expand Up @@ -621,7 +644,7 @@ Clients:
Broker:
- Don't always attempt to call read() for SSL clients, irrespective of whether
they were ready to read or not. Reduces syscalls significantly.
- Possible memory leak fixes.
- Possible memory leak fixes.
- Further fix for bug #1226040: multiple retained messages being delivered for
subscriptions ending in #.
- Fix bridge reconnections when using multiple bridge addresses.
Expand Down Expand Up @@ -1087,7 +1110,7 @@ Client library:
- C++ lib_init(), lib_version() and lib_cleanup() are now in the mosqpp
namespace directly, not mosquittopp class members.
- The Python library is now written in pure Python and so no longer depends on
libmosquitto.
libmosquitto.
- The Python library includes SSL/TLS support.
- The Python library should now be compatible with Python 3.

Expand Down Expand Up @@ -1223,7 +1246,7 @@ Other:
use a username/password.
- Add mosquitto_reconnect() to the client library.
- Add option for compiling with liberal protocol compliance support (enabled
by default).
by default).
- Fix problems with clients reconnecting and old messages remaining in the
message store.
- Display both ip and client id in the log message when a client connects.
Expand Down Expand Up @@ -1309,7 +1332,7 @@ Other:

- Implement support for the password_file option and accompanying
authentication requirements in the broker.
- Implement topic Access Control Lists.
- Implement topic Access Control Lists.
- mosquitto_will_set() and mosquitto_publish() now return
MOSQ_ERR_PAYLOAD_SIZE if the payload is too large (>268,435,455 bytes).
- Bridge support can now be disabled at compile time.
Expand Down Expand Up @@ -1384,7 +1407,7 @@ Other:
- Don't send client will if it is disconnected for exceeding its keepalive
timer.
- Fix client library unsubscribe function incorrectly sending a SUBSCRIBE
command when it should be UNSUBSCRIBE.
command when it should be UNSUBSCRIBE.
- Fix max_inflight_messages and max_queued_messages operation. These
parameters now apply only to QoS 1 and 2 messages and are used regardless of
the client connection state.
Expand Down Expand Up @@ -1527,7 +1550,7 @@ Other:
Fixes bug #529990.
- Treat subscriptions with a trailing slash correctly. This should fix bugs
#530369 and #530099.

0.5.1 - 20100227
================

Expand Down Expand Up @@ -1602,7 +1625,7 @@ Other:
- Set SO_REUSEADDR on the listening socket so restart is much quicker.
- Added support for tracking current heap memory usage - this is published on
the topic "$SYS/broker/heap/current size"
- Added code for logging to stderr, stdout, syslog and topics.
- Added code for logging to stderr, stdout, syslog and topics.
- Added logging to numerous places - still plenty of scope for more.

0.2 - 20091204
Expand Down
12 changes: 10 additions & 2 deletions client/pub_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ and the Eclipse Distribution License is available at
#define STATUS_CONNECTING 0
#define STATUS_CONNACK_RECVD 1
#define STATUS_WAITING 2
#define STATUS_DISCONNECTING 3

/* Global variables for use in callbacks. See sub_client.c for an example of
* using a struct to hold variables for use in callbacks. */
Expand Down Expand Up @@ -414,8 +415,15 @@ int main(int argc, char *argv[])
}
}
if(feof(stdin)){
last_mid = mid_sent;
status = STATUS_WAITING;
if(last_mid == -1){
/* Empty file */
mosquitto_disconnect(mosq);
disconnect_sent = true;
status = STATUS_DISCONNECTING;
}else{
last_mid = mid_sent;
status = STATUS_WAITING;
}
}
}else if(status == STATUS_WAITING){
if(last_mid_sent == last_mid && disconnect_sent == false){
Expand Down
5 changes: 5 additions & 0 deletions examples/mysql_log/mysql_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ void message_callback(struct mosquitto *mosq, void *obj, const struct mosquitto_

bind[0].buffer_type = MYSQL_TYPE_STRING;
bind[0].buffer = message->topic;
bind[0].buffer_length = strlen(message->topic);
// Note: payload is normally a binary blob and could contains
// NULL byte. This sample does not handle it and assume payload is a
// string.
bind[1].buffer_type = MYSQL_TYPE_STRING;
bind[1].buffer = message->payload;
bind[1].buffer_length = message->payloadlen;

mysql_stmt_bind_param(stmt, bind);
mysql_stmt_execute(stmt);
Expand Down
17 changes: 11 additions & 6 deletions lib/mosquitto.c
Original file line number Diff line number Diff line change
Expand Up @@ -1177,15 +1177,20 @@ int mosquitto_loop_write(struct mosquitto *mosq, int max_packets)

bool mosquitto_want_write(struct mosquitto *mosq)
{
bool result = false;
if(mosq->out_packet || mosq->current_out_packet){
return true;
result = true;
}
#ifdef WITH_TLS
}else if(mosq->ssl && mosq->want_write){
return true;
#endif
}else{
return false;
if(mosq->ssl){
if (mosq->want_write) {
result = true;
}else if(mosq->want_connect){
result = false;
}
}
#endif
return result;
}

int mosquitto_opts_set(struct mosquitto *mosq, enum mosq_opt_t option, void *value)
Expand Down
56 changes: 27 additions & 29 deletions lib/net_mosq.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ Copyright (c) 2009-2016 Roger Light <[email protected]>
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
https://www.eclipse.org/legal/epl-v10.html
and the Eclipse Distribution License is available at
https://www.eclipse.org/org/documents/edl-v10.php.
Contributors:
Roger Light - initial implementation and documentation.
*/
Expand Down Expand Up @@ -143,33 +143,39 @@ int net__socket_close(struct mosquitto *mosq)

assert(mosq);
#ifdef WITH_TLS
if(mosq->ssl){
SSL_shutdown(mosq->ssl);
SSL_free(mosq->ssl);
mosq->ssl = NULL;
}
if(mosq->ssl_ctx){
SSL_CTX_free(mosq->ssl_ctx);
mosq->ssl_ctx = NULL;
#ifdef WITH_WEBSOCKETS
if(!mosq->wsi)
#endif
{
if(mosq->ssl){
SSL_shutdown(mosq->ssl);
SSL_free(mosq->ssl);
mosq->ssl = NULL;
}
if(mosq->ssl_ctx){
SSL_CTX_free(mosq->ssl_ctx);
mosq->ssl_ctx = NULL;
}
}
#endif

if((int)mosq->sock >= 0){
#ifdef WITH_BROKER
HASH_DELETE(hh_sock, db->contexts_by_sock, mosq);
#endif
rc = COMPAT_CLOSE(mosq->sock);
mosq->sock = INVALID_SOCKET;
#ifdef WITH_WEBSOCKETS
}else if(mosq->sock == WEBSOCKET_CLIENT){
if(mosq->wsi)
{
if(mosq->state != mosq_cs_disconnecting){
mosq->state = mosq_cs_disconnect_ws;
}
if(mosq->wsi){
libwebsocket_callback_on_writable(mosq->ws_context, mosq->wsi);
}
mosq->sock = INVALID_SOCKET;
libwebsocket_callback_on_writable(mosq->ws_context, mosq->wsi);
}else
#endif
{
if((int)mosq->sock >= 0){
#ifdef WITH_BROKER
HASH_DELETE(hh_sock, db->contexts_by_sock, mosq);
#endif
rc = COMPAT_CLOSE(mosq->sock);
mosq->sock = INVALID_SOCKET;
}
}

#ifdef WITH_BROKER
Expand Down Expand Up @@ -253,7 +259,6 @@ int net__try_connect_step2(struct mosquitto *mosq, uint16_t port, mosq_sock_t *s

/* Set non-blocking */
if(net__socket_nonblock(*sock)){
COMPAT_CLOSE(*sock);
continue;
}

Expand All @@ -268,7 +273,6 @@ int net__try_connect_step2(struct mosquitto *mosq, uint16_t port, mosq_sock_t *s

/* Set non-blocking */
if(net__socket_nonblock(*sock)){
COMPAT_CLOSE(*sock);
continue;
}
break;
Expand Down Expand Up @@ -353,7 +357,6 @@ int net__try_connect(struct mosquitto *mosq, const char *host, uint16_t port, mo
if(!blocking){
/* Set non-blocking */
if(net__socket_nonblock(*sock)){
COMPAT_CLOSE(*sock);
continue;
}
}
Expand All @@ -370,7 +373,6 @@ int net__try_connect(struct mosquitto *mosq, const char *host, uint16_t port, mo
if(blocking){
/* Set non-blocking */
if(net__socket_nonblock(*sock)){
COMPAT_CLOSE(*sock);
continue;
}
}
Expand Down Expand Up @@ -801,7 +803,6 @@ int net__socketpair(mosq_sock_t *pairR, mosq_sock_t *pairW)
continue;
}
if(net__socket_nonblock(spR)){
COMPAT_CLOSE(spR);
COMPAT_CLOSE(listensock);
continue;
}
Expand Down Expand Up @@ -829,7 +830,6 @@ int net__socketpair(mosq_sock_t *pairR, mosq_sock_t *pairW)

if(net__socket_nonblock(spW)){
COMPAT_CLOSE(spR);
COMPAT_CLOSE(spW);
COMPAT_CLOSE(listensock);
continue;
}
Expand All @@ -847,13 +847,11 @@ int net__socketpair(mosq_sock_t *pairR, mosq_sock_t *pairW)
return MOSQ_ERR_ERRNO;
}
if(net__socket_nonblock(sv[0])){
COMPAT_CLOSE(sv[0]);
COMPAT_CLOSE(sv[1]);
return MOSQ_ERR_ERRNO;
}
if(net__socket_nonblock(sv[1])){
COMPAT_CLOSE(sv[0]);
COMPAT_CLOSE(sv[1]);
return MOSQ_ERR_ERRNO;
}
*pairR = sv[0];
Expand Down
11 changes: 7 additions & 4 deletions lib/packet_mosq.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ Copyright (c) 2009-2016 Roger Light <[email protected]>
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
https://www.eclipse.org/legal/epl-v10.html
and the Eclipse Distribution License is available at
https://www.eclipse.org/org/documents/edl-v10.php.
Contributors:
Roger Light - initial implementation and documentation.
*/
Expand Down Expand Up @@ -269,7 +269,11 @@ int packet__write(struct mosquitto *mosq)
}
pthread_mutex_unlock(&mosq->out_packet_mutex);

#if defined(WITH_TLS) && !defined(WITH_BROKER)
if((mosq->state == mosq_cs_connect_pending) || mosq->want_connect){
#else
if(mosq->state == mosq_cs_connect_pending){
#endif
pthread_mutex_unlock(&mosq->current_out_packet_mutex);
return MOSQ_ERR_SUCCESS;
}
Expand Down Expand Up @@ -315,7 +319,7 @@ int packet__write(struct mosquitto *mosq)
}
pthread_mutex_unlock(&mosq->callback_mutex);
}else if(((packet->command)&0xF0) == DISCONNECT){
/* FIXME what cleanup needs doing here?
/* FIXME what cleanup needs doing here?
* incoming/outgoing messages? */
net__socket_close(mosq);

Expand Down Expand Up @@ -533,4 +537,3 @@ int packet__read(struct mosquitto *mosq)
pthread_mutex_unlock(&mosq->msgtime_mutex);
return rc;
}

Loading

0 comments on commit 81cb7ab

Please sign in to comment.