From: Arran Cudbard-Bell Date: Wed, 23 Nov 2016 16:05:00 +0000 (-0500) Subject: Document cf_data functions, and record type correctly. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77d726a670128bee15bde736450baafe1df5fff3;p=thirdparty%2Ffreeradius-server.git Document cf_data functions, and record type correctly. --- diff --git a/src/include/conffile.h b/src/include/conffile.h index 11c0c3e0a8e..bfd17996572 100644 --- a/src/include/conffile.h +++ b/src/include/conffile.h @@ -394,6 +394,8 @@ typedef struct CONF_PARSER { #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, @@ -423,9 +425,10 @@ CONF_SECTION *cf_section_sub_find_name2(CONF_SECTION const *, char const *name1, 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); diff --git a/src/main/client.c b/src/main/client.c index 4839b826019..7919de4f6d5 100644 --- a/src/main/client.c +++ b/src/main/client.c @@ -557,7 +557,7 @@ RADCLIENT_LIST *client_list_parse_section(CONF_SECTION *section, UNUSED bool tls * Be forgiving. If there's already a clients, return * it. Otherwise create a new one. */ - clients = cf_data_find(section, 0, "clients"); + clients = cf_data_find(section, CF_DATA_TYPE_CLIENT, "clients"); if (clients) return clients; /* diff --git a/src/main/conffile.c b/src/main/conffile.c index a2a74c3137e..4f789fb397a 100644 --- a/src/main/conffile.c +++ b/src/main/conffile.c @@ -3998,9 +3998,20 @@ bool cf_item_is_pair(CONF_ITEM const *item) 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; @@ -4009,6 +4020,7 @@ static CONF_DATA *cf_data_alloc(CONF_SECTION *parent, char const *name, 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); @@ -4023,10 +4035,17 @@ static CONF_DATA *cf_data_alloc(CONF_SECTION *parent, char const *name, 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; @@ -4050,11 +4069,19 @@ void *cf_data_find(CONF_SECTION const *cs, int type, char const *name) 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; @@ -4065,7 +4092,7 @@ int cf_data_add(CONF_SECTION *cs, int type, char const *name, void const *data, */ 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)); @@ -4075,8 +4102,15 @@ int cf_data_add(CONF_SECTION *cs, int type, char const *name, void const *data, /** 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; diff --git a/src/main/modules.c b/src/main/modules.c index fb839672d68..fa0d8436342 100644 --- a/src/main/modules.c +++ b/src/main/modules.c @@ -383,7 +383,7 @@ module_instance_t *module_find(CONF_SECTION *modules, char const *asked_name) 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 @@ -886,7 +886,7 @@ static module_instance_t *module_bootstrap(CONF_SECTION *modules, CONF_SECTION * /* * 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; }