diff --git a/ChangeLog.txt b/ChangeLog.txt index e935157b..d2c36b29 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -15,6 +15,8 @@ Client library: identifier integer to the corresponding property name string. - Add `mosquitto_property_next()` to retrieve the next property in a list, for iterating over property lists. +- mosquitto_pub now handles the MQTT v5 retain-available property by never + setting the retain bit. Clients: - Add timeout return code (27) for `mosquitto_sub -W ` and diff --git a/lib/actions.c b/lib/actions.c index 99d03f29..fda66b00 100644 --- a/lib/actions.c +++ b/lib/actions.c @@ -51,6 +51,10 @@ int mosquitto_publish_v5(struct mosquitto *mosq, int *mid, const char *topic, in if(mosq->protocol != mosq_p_mqtt5 && properties) return MOSQ_ERR_NOT_SUPPORTED; if(qos > mosq->maximum_qos) return MOSQ_ERR_QOS_NOT_SUPPORTED; + if(!mosq->retain_available){ + retain = false; + } + if(properties){ if(properties->client_generated){ outgoing_properties = properties; diff --git a/lib/connect.c b/lib/connect.c index f32c2c53..b9e984af 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -78,6 +78,7 @@ static int mosquitto__connect_init(struct mosquitto *mosq, const char *host, int mosq->keepalive = keepalive; mosq->msgs_in.inflight_quota = mosq->msgs_in.inflight_maximum; mosq->msgs_out.inflight_quota = mosq->msgs_out.inflight_maximum; + mosq->retain_available = 1; if(mosq->sockpairR != INVALID_SOCKET){ COMPAT_CLOSE(mosq->sockpairR); diff --git a/lib/handle_connack.c b/lib/handle_connack.c index 379da156..b3c90ed2 100644 --- a/lib/handle_connack.c +++ b/lib/handle_connack.c @@ -97,6 +97,7 @@ int handle__connack(struct mosquitto *mosq) } } + mosquitto_property_read_byte(properties, MQTT_PROP_RETAIN_AVAILABLE, &mosq->retain_available, false); mosquitto_property_read_byte(properties, MQTT_PROP_MAXIMUM_QOS, &mosq->maximum_qos, false); mosquitto_property_read_int16(properties, MQTT_PROP_RECEIVE_MAXIMUM, &mosq->msgs_out.inflight_maximum, false); mosquitto_property_read_int16(properties, MQTT_PROP_SERVER_KEEP_ALIVE, &mosq->keepalive, false); diff --git a/lib/mosquitto_internal.h b/lib/mosquitto_internal.h index de640144..08f20091 100644 --- a/lib/mosquitto_internal.h +++ b/lib/mosquitto_internal.h @@ -329,6 +329,7 @@ struct mosquitto { unsigned int reconnect_delay; unsigned int reconnect_delay_max; bool reconnect_exponential_backoff; + uint8_t retain_available; char threaded; struct mosquitto__packet *out_packet_last; # ifdef WITH_SRV