]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Remove dict_by_attr_name. It's pretty useless now we don't have one namespace per...
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 7 Dec 2020 14:45:17 +0000 (07:45 -0700)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 7 Dec 2020 14:45:17 +0000 (07:45 -0700)
src/lib/util/dict.h
src/lib/util/dict_priv.h
src/lib/util/dict_util.c
src/lib/util/pair_legacy.c
src/modules/rlm_detail/rlm_detail.c
src/modules/rlm_passwd/rlm_passwd.c
src/modules/rlm_sql/rlm_sql.c
src/modules/rlm_sqlippool/rlm_sqlippool.c

index 383c5757936f8489e811242daa9c3bdf716a7dbf..fa54c5dd5376ee376c329ec636ccbe835d23c997 100644 (file)
@@ -494,6 +494,10 @@ ssize_t                    fr_dict_attr_search_by_qualified_oid_substr(fr_dict_attr_err_t *err, f
                                                                    bool fallback)
                                                                    CC_HINT(nonnull(2, 4));
 
+fr_dict_attr_t const   *fr_dict_attr_search_by_qualified_oid(fr_dict_attr_err_t *err,
+                                                             fr_dict_t const *dict_def, char const *attr, bool fallback)
+                                                             CC_HINT(nonnull(3));
+
 ssize_t                        fr_dict_attr_search_by_oid_substr(fr_dict_attr_err_t *err, fr_dict_attr_t const **out,
                                                          fr_dict_t const *dict_def,
                                                          fr_sbuff_t *in, fr_sbuff_term_t const *tt,
@@ -509,10 +513,6 @@ fr_dict_attr_t const       *fr_dict_attr_by_name(fr_dict_attr_err_t *err, fr_dict_attr
                                              char const *attr)
                                              CC_HINT(nonnull(2,3));
 
-fr_dict_attr_t const   *fr_dict_attr_by_qualified_oid(fr_dict_attr_err_t *err,
-                                                      fr_dict_t const *dict_def, char const *attr, bool fallback)
-                                                      CC_HINT(nonnull(3));
-
 fr_dict_attr_t const   *fr_dict_attr_by_type(fr_dict_attr_t const *da, fr_type_t type);
 
 fr_dict_attr_t const   *fr_dict_attr_child_by_da(fr_dict_attr_t const *parent, fr_dict_attr_t const *child) CC_HINT(nonnull);
index 9b8e2aa8d641589c89b7e5a999798219d2a7ba6f..7a755e1b9f61501b8028e3315e8377f12d016227 100644 (file)
@@ -178,8 +178,6 @@ fr_dict_t           *dict_by_protocol_num(unsigned int num);
 
 fr_dict_t              *dict_by_da(fr_dict_attr_t const *da);
 
-fr_dict_t              *dict_by_attr_name(fr_dict_attr_t const **found, char const *name);
-
 bool                   dict_attr_can_have_children(fr_dict_attr_t const *da);
 
 int                    dict_attr_enum_add_name(fr_dict_attr_t *da, char const *name, fr_value_box_t const *value,
index fea3f20c0eb06499489d21525caa0e968a13a3a4..b5eb8bf7f4f1769a5b95ec78b69a8e5c249a0d6d 100644 (file)
@@ -2082,72 +2082,6 @@ fr_dict_t *dict_by_da(fr_dict_attr_t const *da)
        return talloc_get_type_abort(da->dict, fr_dict_t);
 }
 
-/** Dictionary/attribute ctx struct
- *
- */
-typedef struct {
-       fr_dict_t               *found_dict;    //!< Dictionary attribute found in.
-       fr_dict_attr_t const    *found_da;      //!< Resolved attribute.
-       fr_dict_attr_t const    *find;          //!< Attribute to find.
-} dict_attr_search_t;
-
-/** Search for an attribute name in all dictionaries
- *
- * @param[in] data     Dictionary to search in.
- * @param[in] uctx     Attribute to search for.
- * @return
- *     - 0 if attribute not found in dictionary.
- *     - 1 if attribute found in dictionary.
- */
-static int _dict_attr_find_in_dicts(void *data, void *uctx)
-{
-       dict_attr_search_t      *search = uctx;
-       fr_dict_t               *dict;
-       fr_hash_table_t         *namespace;
-
-       if (!data) return 0;    /* We get called with NULL data */
-
-       dict = talloc_get_type_abort(data, fr_dict_t);
-
-       namespace = dict_attr_namespace(dict->root);
-       if (!namespace) return 0;
-
-       search->found_da = fr_hash_table_find_by_data(namespace, search->find);
-       if (!search->found_da) return 0;
-
-       search->found_dict = data;
-
-       return 1;
-}
-
-/** Internal version of #fr_dict_by_attr_name
- *
- * @note For internal use by the dictionary API only.
- *
- * @copybrief fr_dict_by_attr_name
- */
-fr_dict_t *dict_by_attr_name(fr_dict_attr_t const **found, char const *name)
-{
-       fr_dict_attr_t          find = {
-                                       .name = name
-                               };
-       dict_attr_search_t      search = {
-                                       .find = &find
-                               };
-       int                     ret;
-
-       if (found) *found = NULL;
-
-       if (!name || !*name) return NULL;
-
-       ret = fr_hash_table_walk(dict_gctx->protocol_by_name, _dict_attr_find_in_dicts, &search);
-       if (ret == 0) return NULL;
-
-       if (found) *found = search.found_da;
-
-       return search.found_dict;
-}
-
 /** Lookup a protocol by its name
  *
  * @note For internal use by the dictionary API only.
@@ -2191,21 +2125,6 @@ fr_dict_t const *fr_dict_by_da(fr_dict_attr_t const *da)
        return dict_by_da(da);
 }
 
-/** Attempt to locate the protocol dictionary containing an attribute
- *
- * @note This is O(n) and will only return the first instance of the dictionary.
- *
- * @param[out] found   the attribute that was resolved from the name. May be NULL.
- * @param[in] name     the name of the attribute.
- * @return
- *     - the dictionary the attribute was found in.
- *     - NULL if an attribute with the specified name wasn't found in any dictionary.
- */
-fr_dict_t const *fr_dict_by_attr_name(fr_dict_attr_t const **found, char const *name)
-{
-       return dict_by_attr_name(found, name);
-}
-
 /** Look up a vendor by one of its child attributes
  *
  * @param[in] da       The vendor attribute.
@@ -2558,6 +2477,36 @@ ssize_t fr_dict_attr_search_by_oid_substr(fr_dict_attr_err_t *err, fr_dict_attr_
        return dict_attr_search_qualified(err, out, dict_def, in, tt, fallback, fr_dict_attr_by_oid_substr);
 }
 
+/** Locate a qualified #fr_dict_attr_t by its name and a dictionary qualifier
+ *
+ * @param[out] err             Why parsing failed. May be NULL.
+ *                             @see fr_dict_attr_err_t.
+ * @param[in] dict_def         Default dictionary for non-qualified dictionaries.
+ * @param[in] name             Dictionary/Attribute name.
+ * @param[in] fallback         If true, fallback to the internal dictionary.
+ * @return an #fr_dict_attr_err_t value.
+ */
+fr_dict_attr_t const *fr_dict_attr_search_by_qualified_oid(fr_dict_attr_err_t *err, fr_dict_t const *dict_def,
+                                                          char const *name, bool fallback)
+{
+       ssize_t                 slen;
+       fr_sbuff_t              our_name;
+       fr_dict_attr_t const    *da;
+
+       fr_sbuff_init(&our_name, name, strlen(name) + 1);
+
+       slen = fr_dict_attr_search_by_qualified_oid_substr(err, &da, dict_def, &our_name, NULL, fallback);
+       if (slen <= 0) return NULL;
+
+       if ((size_t)slen != fr_sbuff_len(&our_name)) {
+               fr_strerror_printf("Trailing garbage after attr string \"%s\"", name);
+               if (err) *err = FR_DICT_ATTR_PARSE_ERROR;
+               return NULL;
+       }
+
+       return da;
+}
+
 /** Look up a dictionary attribute by a name embedded in another string
  *
  * Find the first invalid attribute name char in the string pointed
@@ -2674,35 +2623,6 @@ fr_dict_attr_t const *fr_dict_attr_by_name(fr_dict_attr_err_t *err, fr_dict_attr
        return dict_attr_by_name(err, parent, name);
 }
 
-/** Locate a qualified #fr_dict_attr_t by its name and a dictionary qualifier
- *
- * @param[out] err             Why parsing failed. May be NULL.
- *                             @see fr_dict_attr_err_t.
- * @param[in] dict_def         Default dictionary for non-qualified dictionaries.
- * @param[in] name             Dictionary/Attribute name.
- * @param[in] fallback         If true, fallback to the internal dictionary.
- * @return an #fr_dict_attr_err_t value.
- */
-fr_dict_attr_t const *fr_dict_attr_by_qualified_oid(fr_dict_attr_err_t *err, fr_dict_t const *dict_def,
-                                                   char const *name, bool fallback)
-{
-       ssize_t                 slen;
-       fr_sbuff_t              our_name;
-       fr_dict_attr_t const    *da;
-
-       fr_sbuff_init(&our_name, name, strlen(name) + 1);
-
-       slen = fr_dict_attr_search_by_qualified_oid_substr(err, &da, dict_def, &our_name, NULL, fallback);
-       if (slen <= 0) return NULL;
-
-       if ((size_t)slen != fr_sbuff_len(&our_name)) {
-               fr_strerror_printf("Trailing garbage after attr string \"%s\"", name);
-               if (err) *err = FR_DICT_ATTR_PARSE_ERROR;
-               return NULL;
-       }
-
-       return da;
-}
 
 /** Lookup a attribute by its its vendor and attribute numbers and data type
  *
index 56d4252cc53f4e9b092c203e16b9cfe97da3b66d..b82c9159c81b2779854623ab13a6a44e0ad38f82 100644 (file)
@@ -175,7 +175,7 @@ fr_pair_t *fr_pair_make(TALLOC_CTX *ctx, fr_dict_t const *dict, fr_pair_list_t *
         *      It's not found in the dictionary, so we use
         *      another method to create the attribute.
         */
-       da = fr_dict_attr_by_qualified_oid(NULL, dict, attrname, true);
+       da = fr_dict_attr_search_by_qualified_oid(NULL, dict, attrname, true);
        if (!da) {
                vp = fr_pair_make_unknown(ctx, dict, attrname, value, op);
                if (!vp) return NULL;
index bdb972a7359827e5b42ac2a5f36705147f388e78..3cb27d3d22d2d53d503afb7951377c9efa2692b1 100644 (file)
@@ -173,7 +173,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf)
                        attr = cf_pair_attr(cf_item_to_pair(ci));
                        if (!attr) continue; /* pair-anoia */
 
-                       da = fr_dict_attr_by_qualified_oid(NULL, dict_radius, attr, false);
+                       da = fr_dict_attr_search_by_qualified_oid(NULL, dict_radius, attr, false);
                        if (!da) {
                                cf_log_perr(conf, "Failed resolving attribute");
                                return -1;
index eafa720145f192124e40bb8ed173bfa5607dc554..cc175702e00809aebdc5b82466caf206f4301549 100644 (file)
@@ -479,7 +479,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf)
                return -1;
        }
 
-       da = fr_dict_attr_by_qualified_oid(NULL, dict_freeradius,
+       da = fr_dict_attr_search_by_qualified_oid(NULL, dict_freeradius,
                                           inst->pwd_fmt->field[key_field], true);
        if (!da) {
                PERROR("Unable to resolve attribute");
index d825569d109c7a0b37446acdd1939f154384904b..3615703ba2959e2baed3359a25cb9099fb1db0b1 100644 (file)
@@ -1075,7 +1075,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf)
                        goto error;
                }
 
-               inst->group_da = fr_dict_attr_by_qualified_oid(NULL, dict_freeradius, group_attribute, false);
+               inst->group_da = fr_dict_attr_search_by_qualified_oid(NULL, dict_freeradius, group_attribute, false);
                if (!inst->group_da) {
                        PERROR("Failed resolving group attribute");
                        goto error;
index a2d7c9c185926268347ac7f4cbd5d9a12be5a520..b08f22e451fbe2b0138d8b449d4a7287b82819ef 100644 (file)
@@ -428,7 +428,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf)
                return -1;
        }
 
-       inst->allocated_address_da = fr_dict_attr_by_qualified_oid(NULL, dict_freeradius,
+       inst->allocated_address_da = fr_dict_attr_search_by_qualified_oid(NULL, dict_freeradius,
                                                                   inst->allocated_address_attr, false);
        if (!inst->allocated_address_da) {
                cf_log_perr(conf, "Failed resolving attribute");