]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
split out separate function
authorAlan T. DeKok <aland@freeradius.org>
Wed, 12 Jul 2023 18:04:54 +0000 (14:04 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 12 Jul 2023 18:04:54 +0000 (14:04 -0400)
so we can create nested VPs, starting from an intermediate point

src/lib/util/pair.c
src/lib/util/pair.h

index 1b1dcedbee10292772e983155a46ab0c15890f35..1bad0bc823a625f849ca1df8e3cfd2df699a50a5 100644 (file)
@@ -449,37 +449,30 @@ fr_pair_t *fr_pair_afrom_child_num(TALLOC_CTX *ctx, fr_dict_attr_t const *parent
 
 /** Create a pair (and all intermediate parents), and append it to the list
  *
- *  If the relevant leaf pair already exists, then a new one is created.
- *
- *  This function is similar to fr_pair_update_by_da_parent(), except that function requires
- *  a parent pair, and this one takes a separate talloc ctx and pair list.
+ *  Unlike fr_pair_afrom_da_nested(), this function starts off at an intermediate ctx and list.
  *
  * @param[in] ctx      for allocated memory, usually a pointer to a #fr_radius_packet_t.
  * @param[out] list    where the created pair is supposed to go.
  * @param[in] da       the da for the pair to create
+ * @param[in] start    the starting depth. If start != 0, we must have ctx==vp at that depth, and list==&vp->vp_group
  * @return
  *     - A new #fr_pair_t.
  *     - NULL on error.
  */
-fr_pair_t *fr_pair_afrom_da_nested(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_attr_t const *da)
+fr_pair_t *fr_pair_afrom_da_depth_nested(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_attr_t const *da, int start)
 {
-       fr_pair_t *vp;
+       fr_pair_t               *vp;
        unsigned int            i;
        TALLOC_CTX              *cur_ctx;
        fr_dict_attr_t const    *find;          /* DA currently being looked for */
        fr_pair_list_t          *cur_list;      /* Current list being searched */
        fr_da_stack_t           da_stack;
 
-       if (da->depth <= 1) {
-               if  (fr_pair_append_by_da(ctx, &vp, list, da) < 0) return NULL;
-               return vp;
-       }
-
        fr_proto_da_stack_build(&da_stack, da);
        cur_list = list;
        cur_ctx = ctx;
 
-       for (i = 0; i <= da->depth; i++) {
+       for (i = start; i <= da->depth; i++) {
                find = da_stack.da[i];
 
                vp = fr_pair_find_by_da(cur_list, NULL, find);
@@ -500,6 +493,32 @@ fr_pair_t *fr_pair_afrom_da_nested(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dic
        return NULL;
 }
 
+/** Create a pair (and all intermediate parents), and append it to the list
+ *
+ *  If the relevant leaf pair already exists, then a new one is created.
+ *
+ *  This function is similar to fr_pair_update_by_da_parent(), except that function requires
+ *  a parent pair, and this one takes a separate talloc ctx and pair list.
+ *
+ * @param[in] ctx      for allocated memory, usually a pointer to a #fr_radius_packet_t.
+ * @param[out] list    where the created pair is supposed to go.
+ * @param[in] da       the da for the pair to create
+ * @return
+ *     - A new #fr_pair_t.
+ *     - NULL on error.
+ */
+fr_pair_t *fr_pair_afrom_da_nested(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_attr_t const *da)
+{
+       if (da->depth <= 1) {
+               fr_pair_t *vp;
+
+               if  (fr_pair_append_by_da(ctx, &vp, list, da) < 0) return NULL;
+               return vp;
+       }
+
+       return fr_pair_afrom_da_depth_nested(ctx, list, da, 0);
+}
+
 /** Copy a single valuepair
  *
  * Allocate a new valuepair and copy the da from the old vp.
index 62976c0c0509fe31fe4c2014480ffd99e4c0e002..d929582f15d1ebf55cc4d9ca91c1e00561c2e24d 100644 (file)
@@ -440,6 +440,8 @@ fr_pair_t   *fr_pair_afrom_child_num(TALLOC_CTX *ctx, fr_dict_attr_t const *parent
 
 fr_pair_t      *fr_pair_afrom_da_nested(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_attr_t const *da) CC_HINT(warn_unused_result) CC_HINT(nonnull(2,3));
 
+fr_pair_t      *fr_pair_afrom_da_depth_nested(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_attr_t const *da, int start) CC_HINT(warn_unused_result) CC_HINT(nonnull(2,3));
+
 fr_pair_t      *fr_pair_copy(TALLOC_CTX *ctx, fr_pair_t const *vp) CC_HINT(nonnull(2)) CC_HINT(warn_unused_result);
 
 int            fr_pair_steal(TALLOC_CTX *ctx, fr_pair_t *vp) CC_HINT(nonnull);