Add retain_available support.
This commit is contained in:
parent
36e8659762
commit
9560c5bac7
@ -628,6 +628,16 @@
|
|||||||
<para>Reloaded on reload signal.</para>
|
<para>Reloaded on reload signal.</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
<varlistentry>
|
||||||
|
<term><option>retain_available</option> [ true | false ]</term>
|
||||||
|
<listitem>
|
||||||
|
<para>If set to false, then retained messages are not
|
||||||
|
supported. Clients that send a message with the retain
|
||||||
|
bit will be disconnected if this option is set to
|
||||||
|
false. Defaults to true.</para>
|
||||||
|
<para>Reloaded on reload signal.</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>retained_persistence</option> [ true | false ]</term>
|
<term><option>retained_persistence</option> [ true | false ]</term>
|
||||||
<listitem>
|
<listitem>
|
||||||
|
@ -149,6 +149,12 @@
|
|||||||
#per_listener_settings false
|
#per_listener_settings false
|
||||||
|
|
||||||
|
|
||||||
|
# Set to false to disable retained message support. If a client publishes a
|
||||||
|
# message with the retain bit set, it will be disconnected if this is set to
|
||||||
|
# false.
|
||||||
|
#retain_available true
|
||||||
|
|
||||||
|
|
||||||
# =================================================================
|
# =================================================================
|
||||||
# Default listener
|
# Default listener
|
||||||
# =================================================================
|
# =================================================================
|
||||||
|
@ -219,6 +219,7 @@ static void config__init_reload(struct mosquitto_db *db, struct mosquitto__confi
|
|||||||
config->persistence_file = NULL;
|
config->persistence_file = NULL;
|
||||||
config->persistent_client_expiration = 0;
|
config->persistent_client_expiration = 0;
|
||||||
config->queue_qos0_messages = false;
|
config->queue_qos0_messages = false;
|
||||||
|
config->retain_available = true;
|
||||||
config->set_tcp_nodelay = false;
|
config->set_tcp_nodelay = false;
|
||||||
config->sys_interval = 10;
|
config->sys_interval = 10;
|
||||||
config->upgrade_outgoing_qos = false;
|
config->upgrade_outgoing_qos = false;
|
||||||
@ -1729,6 +1730,8 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct
|
|||||||
#else
|
#else
|
||||||
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Bridge support not available.");
|
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Bridge support not available.");
|
||||||
#endif
|
#endif
|
||||||
|
}else if(!strcmp(token, "retain_available")){
|
||||||
|
if(conf__parse_bool(&token, token, &config->retain_available, saveptr)) return MOSQ_ERR_INVAL;
|
||||||
}else if(!strcmp(token, "retry_interval")){
|
}else if(!strcmp(token, "retry_interval")){
|
||||||
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: The retry_interval option is no longer available.");
|
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: The retry_interval option is no longer available.");
|
||||||
}else if(!strcmp(token, "round_robin")){
|
}else if(!strcmp(token, "round_robin")){
|
||||||
|
@ -575,6 +575,10 @@ int db__messages_easy_queue(struct mosquitto_db *db, struct mosquitto *context,
|
|||||||
topic_heap = mosquitto__strdup(topic);
|
topic_heap = mosquitto__strdup(topic);
|
||||||
if(!topic_heap) return MOSQ_ERR_INVAL;
|
if(!topic_heap) return MOSQ_ERR_INVAL;
|
||||||
|
|
||||||
|
if(db->config->retain_available == false){
|
||||||
|
retain = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if(UHPA_ALLOC(payload_uhpa, payloadlen) == 0){
|
if(UHPA_ALLOC(payload_uhpa, payloadlen) == 0){
|
||||||
mosquitto__free(topic_heap);
|
mosquitto__free(topic_heap);
|
||||||
return MOSQ_ERR_NOMEM;
|
return MOSQ_ERR_NOMEM;
|
||||||
|
@ -236,6 +236,14 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
|
|||||||
password_flag = connect_flags & 0x40;
|
password_flag = connect_flags & 0x40;
|
||||||
username_flag = connect_flags & 0x80;
|
username_flag = connect_flags & 0x80;
|
||||||
|
|
||||||
|
if(will && will_retain && db->config->retain_available == false){
|
||||||
|
if(protocol_version == mosq_p_mqtt5){
|
||||||
|
send__connack(db, context, 0, MQTT_RC_RETAIN_NOT_SUPPORTED);
|
||||||
|
}
|
||||||
|
rc = 1;
|
||||||
|
goto handle_connect_error;
|
||||||
|
}
|
||||||
|
|
||||||
if(packet__read_uint16(&context->in_packet, &(context->keepalive))){
|
if(packet__read_uint16(&context->in_packet, &(context->keepalive))){
|
||||||
rc = 1;
|
rc = 1;
|
||||||
goto handle_connect_error;
|
goto handle_connect_error;
|
||||||
|
@ -68,6 +68,13 @@ int handle__publish(struct mosquitto_db *db, struct mosquitto *context)
|
|||||||
}
|
}
|
||||||
retain = (header & 0x01);
|
retain = (header & 0x01);
|
||||||
|
|
||||||
|
if(retain && db->config->retain_available == false){
|
||||||
|
if(context->protocol == mosq_p_mqtt5){
|
||||||
|
send__disconnect(context, MQTT_RC_RETAIN_NOT_SUPPORTED, NULL);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if(packet__read_string(&context->in_packet, &topic, &slen)) return 1;
|
if(packet__read_string(&context->in_packet, &topic, &slen)) return 1;
|
||||||
if(!slen){
|
if(!slen){
|
||||||
/* Invalid publish topic, disconnect client. */
|
/* Invalid publish topic, disconnect client. */
|
||||||
|
@ -268,6 +268,7 @@ struct mosquitto__config {
|
|||||||
char *pid_file;
|
char *pid_file;
|
||||||
bool queue_qos0_messages;
|
bool queue_qos0_messages;
|
||||||
bool per_listener_settings;
|
bool per_listener_settings;
|
||||||
|
bool retain_available;
|
||||||
bool set_tcp_nodelay;
|
bool set_tcp_nodelay;
|
||||||
int sys_interval;
|
int sys_interval;
|
||||||
bool upgrade_outgoing_qos;
|
bool upgrade_outgoing_qos;
|
||||||
|
@ -44,6 +44,13 @@ int send__connack(struct mosquitto_db *db, struct mosquitto *context, int ack, i
|
|||||||
packet->command = CMD_CONNACK;
|
packet->command = CMD_CONNACK;
|
||||||
packet->remaining_length = 2;
|
packet->remaining_length = 2;
|
||||||
if(context->protocol == mosq_p_mqtt5){
|
if(context->protocol == mosq_p_mqtt5){
|
||||||
|
if(reason_code < 128 && db->config->retain_available == false){
|
||||||
|
rc = mosquitto_property_add_byte(&properties, MQTT_PROP_RETAIN_AVAILABLE, 0);
|
||||||
|
if(rc){
|
||||||
|
mosquitto__free(packet);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
}
|
||||||
proplen = property__get_length_all(properties);
|
proplen = property__get_length_all(properties);
|
||||||
varbytes = packet__varint_bytes(proplen);
|
varbytes = packet__varint_bytes(proplen);
|
||||||
packet->remaining_length += proplen + varbytes;
|
packet->remaining_length += proplen + varbytes;
|
||||||
|
Loading…
Reference in New Issue
Block a user