From: Alan T. DeKok Date: Wed, 27 Jul 2022 19:17:22 +0000 (-0400) Subject: add fr_edit_list_pair_delete_by_da() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7adf6124dd5f94f0fd079da413567e395d84afc1;p=thirdparty%2Ffreeradius-server.git add fr_edit_list_pair_delete_by_da() which mirrors fr_pair_delete_by_da() --- diff --git a/src/lib/util/edit.c b/src/lib/util/edit.c index 6bb88caaf78..0a8954a8cd3 100644 --- a/src/lib/util/edit.c +++ b/src/lib/util/edit.c @@ -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. diff --git a/src/lib/util/edit.h b/src/lib/util/edit.h index f3ef05a2876..3cc0d66cf34 100644 --- a/src/lib/util/edit.h +++ b/src/lib/util/edit.h @@ -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));