]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add fr_pair_sublist_copy() function
authorNick Porter <nick@portercomputing.co.uk>
Wed, 6 Jan 2021 11:31:32 +0000 (11:31 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 21 Jan 2021 23:05:49 +0000 (23:05 +0000)
src/lib/util/dpair.c
src/lib/util/dpair.h

index 18555af47442f8e71aa98d35718b05f9f9e19695..1f31806a1226cfee2de8322c3867da3786ee10d6 100644 (file)
@@ -1540,6 +1540,44 @@ int fr_pair_list_copy_by_ancestor(TALLOC_CTX *ctx, fr_pair_list_t *to,
        return cnt;
 }
 
+/** Duplicate a list of pairs starting at a particular item
+ *
+ * Copy all pairs from 'from' regardless of tag, attribute or vendor, starting at 'item'.
+ *
+ * @param[in] ctx      for new #fr_pair_t (s) to be allocated in.
+ * @param[in] to       where to copy attributes to.
+ * @param[in] from     whence to copy #fr_pair_t (s).
+ * @param[in] item     to start copying at
+ * @return
+ *     - >0 the number of attributes copied.
+ *     - 0 if no attributes copied.
+ *     - -1 on error.
+ */
+int fr_pair_sublist_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from, fr_pair_t *item)
+{
+       fr_pair_list_t  tmp_list;
+       fr_pair_t       *vp, *new_vp;
+       int             cnt = 0;
+
+       fr_pair_list_init(&tmp_list);
+
+       for (vp = item;
+            vp;
+            vp = fr_pair_list_next(from, vp), cnt++) {
+               VP_VERIFY(vp);
+               new_vp = fr_pair_copy(ctx, vp);
+               if (!new_vp) {
+                       fr_pair_list_free(&tmp_list);
+                       return -1;
+               }
+               fr_pair_add(&tmp_list, new_vp);
+       }
+
+       fr_dlist_move(&to->head, &tmp_list.head);
+
+       return cnt;
+}
+
 /** Free/zero out value (or children) of a given VP
  *
  * @param[in] vp to clear value from.
index b470c50238736ec28e4ebd8ad3f0e19ce175c4d7..5dea44a3bb81f1b85bba3c85582be5c8a86aa54c 100644 (file)
@@ -282,6 +282,7 @@ int         fr_pair_list_copy_by_da(TALLOC_CTX *ctx, fr_pair_list_t *to,
                                        fr_pair_list_t *from, fr_dict_attr_t const *da, unsigned int count);
 int            fr_pair_list_copy_by_ancestor(TALLOC_CTX *ctx, fr_pair_list_t *to,
                                              fr_pair_list_t *from, fr_dict_attr_t const *parent_da, unsigned int count);
+int            fr_pair_sublist_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from, fr_pair_t *item);
 void           fr_tmp_pair_list_move(fr_pair_list_t *dst, fr_pair_list_t *tmp_list);
 
 /** @hidecallergraph */