]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add fr_edit_list_pair_delete_by_da()
authorAlan T. DeKok <aland@freeradius.org>
Wed, 27 Jul 2022 19:17:22 +0000 (15:17 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 27 Jul 2022 19:17:22 +0000 (15:17 -0400)
which mirrors fr_pair_delete_by_da()

src/lib/util/edit.c
src/lib/util/edit.h

index 6bb88caaf78a4e142fc8a1eba0bd8ac91e1a309f..0a8954a8cd33c9c8121a2a1c86b181dd0d1e5c36 100644 (file)
@@ -513,6 +513,37 @@ int fr_edit_list_pair_delete(fr_edit_list_t *el, fr_pair_list_t *list, fr_pair_t
        return edit_record(el, FR_EDIT_DELETE, vp, list, NULL);
 }
 
+/** Delete VPs with a matching da
+ *
+ *  This function mirrors fr_pair_delete_by_da()
+ */
+int fr_edit_list_pair_delete_by_da(fr_edit_list_t *el, fr_pair_list_t *list, fr_dict_attr_t const *da)
+{
+       fr_pair_t *vp, *next;
+
+       if (!el) {
+               fr_pair_delete_by_da(list, da);
+               return 0;
+       }
+
+       /*
+        *      Delete all VPs with a matching da.
+        */
+       for (vp = fr_pair_list_head(list);
+            vp != NULL;
+            vp = next) {
+               next = fr_pair_list_next(list, vp);
+               if (vp->da != da) continue;
+
+               (void) fr_pair_remove(list, vp);
+
+               if (edit_record(el, FR_EDIT_DELETE, vp, list, NULL) < 0) return -1;
+       }
+
+       return 0;
+}
+
+
 /** Record the value of a leaf #fr_value_box_t
  *
  *  After this function returns, it's safe to edit the pair.
index f3ef05a2876fd652753c1df5857df5e46bcc766f..3cc0d66cf34a76b71650c2c8e1707b0bd9172fe2 100644 (file)
@@ -52,6 +52,8 @@ int fr_edit_list_insert_pair_after(fr_edit_list_t *el, fr_pair_list_t *list, fr_
 
 int fr_edit_list_pair_delete(fr_edit_list_t *el, fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull(2,3));
 
+int fr_edit_list_pair_delete_by_da(fr_edit_list_t *el, fr_pair_list_t *list, fr_dict_attr_t const *da) CC_HINT(nonnull(2,3));
+
 int fr_edit_list_save_pair_value(fr_edit_list_t *el, fr_pair_t *vp) CC_HINT(nonnull(2));
 
 int fr_edit_list_replace_pair_value(fr_edit_list_t *el, fr_pair_t *vp, fr_value_box_t *box) CC_HINT(nonnull(2,3));