#define CONF_PARSER_TERMINATOR { .name = NULL, .type = ~(UINT32_MAX - 1), \
.offset = 0, .data = NULL, .dflt = NULL, .quote = T_INVALID }
+typedef void (*cf_data_free)(void *);
+
void cf_file_check_user(uid_t uid, gid_t gid);
CONF_PAIR *cf_pair_alloc(CONF_SECTION *parent, char const *attr, char const *value,
char const *cf_section_value_find(CONF_SECTION const *, char const *attr);
CONF_SECTION *cf_top_section(CONF_SECTION *cs);
-void *cf_data_find(CONF_SECTION const *, int type, char const *);
-int cf_data_add(CONF_SECTION *, int type, char const *, void const *, void (*)(void *));
-void *cf_data_remove(CONF_SECTION *cs, int type, char const *name);
+void *cf_data_find(CONF_SECTION const *cs, cf_data_type_t type, char const *name);
+int cf_data_add(CONF_SECTION *cs, cf_data_type_t type, char const *name,
+ void const *data, cf_data_free data_free);
+void *cf_data_remove(CONF_SECTION *cs, cf_data_type_t type, char const *name);
char const *cf_pair_attr(CONF_PAIR const *pair);
char const *cf_pair_value(CONF_PAIR const *pair);
return item->type == CONF_ITEM_PAIR;
}
-
-static CONF_DATA *cf_data_alloc(CONF_SECTION *parent, char const *name,
- void const *data, void (*data_free)(void *))
+/** Allocate a new user data container
+ *
+ * @param[in] parent conf section.
+ * @param[in] type of user data. Used for name spacing and walking over a specific
+ * type of user data.
+ * @param[in] name String identifier of the user data.
+ * @param[in] data being added.
+ * @param[in] data_free function, called when the parent CONF_SECTION is being freed.
+ * @return
+ * - CONF_DATA on success.
+ * - NULL on error.
+ */
+static CONF_DATA *cf_data_alloc(CONF_SECTION *parent, cf_data_type_t type, char const *name,
+ void const *data, cf_data_free data_free)
{
CONF_DATA *cd;
cd->item.type = CONF_ITEM_DATA;
cd->item.parent = parent;
+ cd->type = type;
cd->name = talloc_typed_strdup(cd, name);
if (!cd->name) {
talloc_free(cd);
return cd;
}
-/*
- * Find data from a particular section.
+/** Find user data in a config section
+ *
+ * @param[in] cs to add data to.
+ * @param[in] type of user data. Used for name spacing and walking over a specific
+ * type of user data.
+ * @param[in] name String identifier of the user data.
+ * @return
+ * - The user data.
+ * - NULL if no user data exists.
*/
-void *cf_data_find(CONF_SECTION const *cs, int type, char const *name)
+void *cf_data_find(CONF_SECTION const *cs, cf_data_type_t type, char const *name)
{
if (!cs || !name) return NULL;
return NULL;
}
-
-/*
- * Add named data to a configuration section.
+/** Add user data to a config section
+ *
+ * @param[in] cs to add data to.
+ * @param[in] type of user data. Used for name spacing and walking over a specific
+ * type of user data.
+ * @param[in] name String identifier of the user data.
+ * @param[in] data to add.
+ * @param[in] data_free Function to free user data when the CONF_SECTION is freed.
+ * @return
+ * - 0 on success.
+ * - -1 on error.
*/
-int cf_data_add(CONF_SECTION *cs, int type, char const *name, void const *data, void (*data_free)(void *))
+int cf_data_add(CONF_SECTION *cs, cf_data_type_t type, char const *name, void const *data, cf_data_free data_free)
{
CONF_DATA *cd;
*/
if (cf_data_find(cs, type, name) != NULL) return -1;
- cd = cf_data_alloc(cs, name, data, data_free);
+ cd = cf_data_alloc(cs, type, name, data, data_free);
if (!cd) return -1;
cf_item_add(cs, cf_data_to_item(cd));
/** Remove named data from a configuration section
*
+ * @param[in] cs to remove data from.
+ * @param[in] type of user data. Used for name spacing and walking over a specific
+ * type of user data.
+ * @param[in] name String identifier of the user data.
+ * @return
+ * - The user data.
+ * - NULL if no matching data is found.
*/
-void *cf_data_remove(CONF_SECTION *cs, int type, char const *name)
+void *cf_data_remove(CONF_SECTION *cs, cf_data_type_t type, char const *name)
{
CONF_DATA mycd;
CONF_DATA *cd;
instance_name = asked_name;
if (instance_name[0] == '-') instance_name++;
- return (module_instance_t *)cf_data_find(modules, CF_DATA_TYPE_CONNECTION_POOL, instance_name);
+ return (module_instance_t *)cf_data_find(modules, CF_DATA_TYPE_MODULE_INSTANCE, instance_name);
}
/** Find an existing module instance and verify it implements the specified method
/*
* Remember the module for later.
*/
- cf_data_add(modules, CF_DATA_TYPE_CONNECTION_POOL, instance->name, instance, NULL);
+ cf_data_add(modules, CF_DATA_TYPE_MODULE_INSTANCE, instance->name, instance, NULL);
return instance;
}