mirror of
https://github.com/eclipse/mosquitto.git
synced 2025-05-08 16:52:13 +08:00
Add retain_available support.
This commit is contained in:
parent
36e8659762
commit
9560c5bac7
@ -628,6 +628,16 @@
|
||||
<para>Reloaded on reload signal.</para>
|
||||
</listitem>
|
||||
</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>
|
||||
<term><option>retained_persistence</option> [ true | false ]</term>
|
||||
<listitem>
|
||||
|
@ -149,6 +149,12 @@
|
||||
#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
|
||||
# =================================================================
|
||||
|
@ -219,6 +219,7 @@ static void config__init_reload(struct mosquitto_db *db, struct mosquitto__confi
|
||||
config->persistence_file = NULL;
|
||||
config->persistent_client_expiration = 0;
|
||||
config->queue_qos0_messages = false;
|
||||
config->retain_available = true;
|
||||
config->set_tcp_nodelay = false;
|
||||
config->sys_interval = 10;
|
||||
config->upgrade_outgoing_qos = false;
|
||||
@ -1729,6 +1730,8 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct
|
||||
#else
|
||||
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Bridge support not available.");
|
||||
#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")){
|
||||
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: The retry_interval option is no longer available.");
|
||||
}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);
|
||||
if(!topic_heap) return MOSQ_ERR_INVAL;
|
||||
|
||||
if(db->config->retain_available == false){
|
||||
retain = 0;
|
||||
}
|
||||
|
||||
if(UHPA_ALLOC(payload_uhpa, payloadlen) == 0){
|
||||
mosquitto__free(topic_heap);
|
||||
return MOSQ_ERR_NOMEM;
|
||||
|
@ -236,6 +236,14 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
|
||||
password_flag = connect_flags & 0x40;
|
||||
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))){
|
||||
rc = 1;
|
||||
goto handle_connect_error;
|
||||
|
@ -68,6 +68,13 @@ int handle__publish(struct mosquitto_db *db, struct mosquitto *context)
|
||||
}
|
||||
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(!slen){
|
||||
/* Invalid publish topic, disconnect client. */
|
||||
|
@ -268,6 +268,7 @@ struct mosquitto__config {
|
||||
char *pid_file;
|
||||
bool queue_qos0_messages;
|
||||
bool per_listener_settings;
|
||||
bool retain_available;
|
||||
bool set_tcp_nodelay;
|
||||
int sys_interval;
|
||||
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->remaining_length = 2;
|
||||
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);
|
||||
varbytes = packet__varint_bytes(proplen);
|
||||
packet->remaining_length += proplen + varbytes;
|
||||
|
Loading…
x
Reference in New Issue
Block a user