Add mosquitto_persistence_location() for plugins.

pull/2527/head
Roger A. Light 3 years ago
parent 1da29c9e51
commit 5731dd8653

@ -105,6 +105,8 @@ Plugins / plugin interface:
network loop, to give chance for PUBACK/PUBREC to be sent. Closes #2474.
- Add MOSQ_EVT_SUBSCRIBE and MOSQ_EVT_UNSUBSCRIBE events that are called when
subscribe/unsubscribes actually succeed.
- Add `mosquitto_persistence_location()` for plugins to use to find a valid
location for storing persistent data.
Client library:
- Add MOSQ_OPT_DISABLE_SOCKETPAIR to allow the disabling of the socketpair

@ -1148,6 +1148,20 @@ int mosquitto_persist_retain_msg_set(const char *topic, uint64_t store_id);
*/
int mosquitto_persist_retain_msg_delete(const char *topic);
/* Function: mosquitto_persistence_location
*
* Returns the `persistence_location` config option, or the contents of the
* MOSQUITTO_PERSISTENCE_LOCATION environment variable, if set.
*
* This location should be used by plugins needing to store persistent data.
* Use of sub directories is recommended.
*
* Returns:
* A valid pointer to the persistence location string
* A NULL pointer if neither the option nor the variable are set
*/
const char *mosquitto_persistence_location(void);
#ifdef __cplusplus
}
#endif

@ -485,6 +485,12 @@
# Default is an empty string (current directory).
# Set to e.g. /var/lib/mosquitto if running as a proper service on Linux or
# similar.
#
# Can also be defined by setting the MOSQUITTO_PERSISTENCE_LOCATION environment
# variable prior to running the broker. If both the config file option and the
# environment variable are set, the environment variable takes precedent.
#
# This can also be used by plugins using the mosquitto_persistence_location() function.
#persistence_location

@ -564,6 +564,14 @@ int config__parse_args(struct mosquitto__config *config, int argc, char *argv[])
if(db.verbose){
config->log_type = UINT_MAX;
}
if(getenv("MOSQUITTO_PERSISTENCE_LOCATION")){
mosquitto__FREE(config->persistence_location);
config->persistence_location = mosquitto_strdup(getenv("MOSQUITTO_PERSISTENCE_LOCATION"));
if(!config->persistence_location){
return MOSQ_ERR_NOMEM;
}
}
return config__check(config);
}

@ -23,6 +23,7 @@ _mosquitto_kick_client_by_username
_mosquitto_log_printf
_mosquitto_log_vprintf
_mosquitto_malloc
_mosquitto_persistence_location
_mosquitto_persist_base_msg_add
_mosquitto_persist_base_msg_delete
_mosquitto_persist_client_add

@ -35,6 +35,7 @@
mosquitto_persist_client_update;
mosquitto_persist_retain_msg_delete;
mosquitto_persist_retain_msg_set;
mosquitto_persistence_location;
mosquitto_plugin_set_info;
mosquitto_property_add_binary;
mosquitto_property_add_byte;

@ -865,3 +865,8 @@ BROKER_EXPORT int mosquitto_broker_node_id_set(uint16_t id)
return MOSQ_ERR_SUCCESS;
}
}
BROKER_EXPORT const char *mosquitto_persistence_location(void)
{
return db.config->persistence_location;
}

Loading…
Cancel
Save