]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Document cf_data functions, and record type correctly.
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 23 Nov 2016 16:05:00 +0000 (11:05 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 23 Nov 2016 16:05:00 +0000 (11:05 -0500)
src/include/conffile.h
src/main/client.c
src/main/conffile.c
src/main/modules.c

index 11c0c3e0a8e39a80b4a20f22dcac02c5dd4e43ea..bfd1799657276f5f69f5d7065792f29661477c5d 100644 (file)
@@ -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);
index 4839b826019da0f104af484ebb319fadde548931..7919de4f6d52c0058a10f5c4a7e494b11c48ed51 100644 (file)
@@ -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;
 
        /*
index a2a74c3137e259f8854535f4341476a9f2982a3b..4f789fb397a43e21373a5ca4d29e00839a6cd7e8 100644 (file)
@@ -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;
index fb839672d681dd468d47716ef174ed2cd0ce20be..fa0d843634251f83fd818bbc7cc4d348c51d953c 100644 (file)
@@ -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;
 }