]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add fr_pair_find_by_ancestor
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 21 Mar 2021 20:27:29 +0000 (20:27 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 31 Mar 2021 15:07:57 +0000 (16:07 +0100)
src/lib/util/pair.c
src/lib/util/pair.h

index afd586b3e9d15c6ee6684a6d5ea5617fcaff197f..de0c37e101e2237b300aef1ed26eb123941e98f2 100644 (file)
@@ -499,7 +499,7 @@ void *fr_pair_iter_next_by_ancestor(fr_dlist_head_t *list, void *to_eval, void *
        return c;
 }
 
-/** Find the pair with the matching DAs
+/** Find a pair with a matching da
  *
  * @param[in] list     to search in.
  * @param[in] da       to look for in the list.
@@ -511,7 +511,7 @@ void *fr_pair_iter_next_by_ancestor(fr_dlist_head_t *list, void *to_eval, void *
  */
 fr_pair_t *fr_pair_find_by_da(fr_pair_list_t const *list, fr_dict_attr_t const *da)
 {
-       fr_pair_t       *vp;
+       fr_pair_t       *vp = NULL;
 
        if (fr_dlist_empty(&list->head)) return NULL;
 
@@ -519,10 +519,32 @@ fr_pair_t *fr_pair_find_by_da(fr_pair_list_t const *list, fr_dict_attr_t const *
 
        if (!da) return NULL;
 
-       for (vp = fr_pair_list_head(list); vp != NULL; vp = fr_pair_list_next(list, vp)) if (da == vp->da) return vp;
+       while ((vp = fr_pair_list_next(list, vp))) if (da == vp->da) return vp;
        return NULL;
 }
 
+/** Find a pair which has the specified ancestor
+ *
+ * @param[in] list     to search in.
+ * @param[in] ancestor to look for in the list.
+ * @return
+ *     - first matching fr_pair_t.
+ *     - NULL if no fr_pair_ts match.
+ *
+ * @hidecallergraph
+ */
+fr_pair_t *fr_pair_find_by_ancestor(fr_pair_list_t const *list, fr_dict_attr_t const *ancestor)
+{
+       fr_pair_t       *vp = NULL;
+
+       while ((vp = fr_pair_list_next(list, vp))) {
+               if (!fr_dict_attr_common_parent(ancestor, vp->da, true)) continue;
+
+               return vp;
+       }
+
+       return NULL;
+}
 
 /** Find the pair with the matching attribute by vendor id and attribute number.
  *
index 9c110838c63b24a7afbf2bd7a53766effcfe518f..ba0678103373b16bf0b3f1f76178cd681dd9044c 100644 (file)
@@ -229,6 +229,8 @@ static inline fr_pair_t *fr_dcursor_iter_by_ancestor_init(fr_dcursor_t *cursor,
 /** @hidecallergraph */
 fr_pair_t      *fr_pair_find_by_da(fr_pair_list_t const *list, fr_dict_attr_t const *da);
 
+fr_pair_t      *fr_pair_find_by_ancestor(fr_pair_list_t const *list, fr_dict_attr_t const *ancestor);
+
 fr_pair_t      *fr_pair_find_by_num(fr_pair_list_t *list, unsigned int vendor, unsigned int attr);
 
 fr_pair_t      *fr_pair_find_by_child_num(fr_pair_list_t *list, fr_dict_attr_t const *parent, unsigned int attr);