From: Alan T. DeKok Date: Fri, 12 Nov 2021 16:34:23 +0000 (-0500) Subject: remove INSERT_BEFORE, and update API X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=727daa822a6f096160b7789898210630b6b73c23;p=thirdparty%2Ffreeradius-server.git remove INSERT_BEFORE, and update API --- diff --git a/src/lib/util/edit.c b/src/lib/util/edit.c index 879e3884ca..038020af51 100644 --- a/src/lib/util/edit.c +++ b/src/lib/util/edit.c @@ -28,6 +28,13 @@ RCSID("$Id$") #include #include "edit.h" +typedef enum { + FR_EDIT_INVALID = 0, + FR_EDIT_DELETE, //!< delete a VP + FR_EDIT_VALUE, //!< edit a VP in place + FR_EDIT_INSERT, //!< insert a VP into a list, after another one. +} fr_edit_op_t; + /** Track a series of edits. * */ @@ -151,7 +158,7 @@ void fr_edit_list_abort(fr_edit_list_t *el) * other modification to structural types, we MUST instead call * insert / delete on the vp_group. */ -int fr_edit_list_record(fr_edit_list_t *el, fr_edit_op_t op, fr_pair_t *vp, fr_pair_list_t *list, fr_pair_t *ref) +static int edit_record(fr_edit_list_t *el, fr_edit_op_t op, fr_pair_t *vp, fr_pair_list_t *list, fr_pair_t *ref) { fr_edit_t *e; @@ -332,6 +339,22 @@ int fr_edit_list_record(fr_edit_list_t *el, fr_edit_op_t op, fr_pair_t *vp, fr_p return 0; } +int fr_edit_list_insert(fr_edit_list_t *el, fr_pair_t *vp, fr_pair_list_t *list, fr_pair_t *prev) +{ + return edit_record(el, FR_EDIT_INSERT, vp, list, prev); +} + +int fr_edit_list_delete(fr_edit_list_t *el, fr_pair_t *vp, fr_pair_list_t *list) +{ + return edit_record(el, FR_EDIT_DELETE, vp, list, NULL); +} + +int fr_edit_list_record(fr_edit_list_t *el, fr_pair_t *vp) +{ + return edit_record(el, FR_EDIT_VALUE, vp, NULL, NULL); +} + + /** Finalize the edits when we destroy the edit list. * * Which in large part means freeing the VPs which have been deleted, diff --git a/src/lib/util/edit.h b/src/lib/util/edit.h index 5e77f08555..13d3e1ba4b 100644 --- a/src/lib/util/edit.h +++ b/src/lib/util/edit.h @@ -31,20 +31,17 @@ RCSIDH(map_h, "$Id$") extern "C" { #endif -typedef enum { - FR_EDIT_INVALID = 0, - FR_EDIT_DELETE, //!< delete a VP - FR_EDIT_VALUE, //!< edit a VP in place - FR_EDIT_INSERT, //!< insert a VP into a list, after another one. -} fr_edit_op_t; - typedef struct fr_edit_list_s fr_edit_list_t; fr_edit_list_t *fr_edit_list_alloc(TALLOC_CTX *ctx); void fr_edit_list_abort(fr_edit_list_t *el); -int fr_edit_list_record(fr_edit_list_t *el, fr_edit_op_t op, fr_pair_t *vp, fr_pair_list_t *list, fr_pair_t *prev); +int fr_edit_list_insert(fr_edit_list_t *el, fr_pair_t *vp, fr_pair_list_t *list, fr_pair_t *prev); + +int fr_edit_list_delete(fr_edit_list_t *el, fr_pair_t *vp, fr_pair_list_t *list); + +int fr_edit_list_record(fr_edit_list_t *el, fr_pair_t *vp); #ifdef __cplusplus } diff --git a/src/lib/util/edit_tests.c b/src/lib/util/edit_tests.c index f787189a14..1eb8753a76 100644 --- a/src/lib/util/edit_tests.c +++ b/src/lib/util/edit_tests.c @@ -132,7 +132,7 @@ static void test_pair_delete_head(void) el = fr_edit_list_alloc(NULL); fr_assert(el != NULL); - rcode = fr_edit_list_record(el, FR_EDIT_DELETE, vp, &local_pairs, NULL); + rcode = fr_edit_list_delete(el, vp, &local_pairs); TEST_CHECK(rcode == 0); talloc_free(el); @@ -165,7 +165,7 @@ static void test_pair_delete_head_abort(void) el = fr_edit_list_alloc(NULL); fr_assert(el != NULL); - rcode = fr_edit_list_record(el, FR_EDIT_DELETE, vp, &local_pairs, NULL); + rcode = fr_edit_list_delete(el, vp, &local_pairs); TEST_CHECK(rcode == 0); count = fr_pair_list_len(&local_pairs); @@ -201,7 +201,7 @@ static void test_pair_delete_middle(void) el = fr_edit_list_alloc(NULL); fr_assert(el != NULL); - rcode = fr_edit_list_record(el, FR_EDIT_DELETE, vp, &local_pairs, NULL); + rcode = fr_edit_list_delete(el, vp, &local_pairs); TEST_CHECK(rcode == 0); talloc_free(el); @@ -240,7 +240,7 @@ static void test_pair_delete_middle_abort(void) el = fr_edit_list_alloc(NULL); fr_assert(el != NULL); - rcode = fr_edit_list_record(el, FR_EDIT_DELETE, middle, &local_pairs, NULL); + rcode = fr_edit_list_delete(el, middle, &local_pairs); TEST_CHECK(rcode == 0); count = fr_pair_list_len(&local_pairs); @@ -282,13 +282,13 @@ static void test_pair_delete_multiple(void) el = fr_edit_list_alloc(NULL); fr_assert(el != NULL); - rcode = fr_edit_list_record(el, FR_EDIT_DELETE, vp, &local_pairs, NULL); /* middle */ + rcode = fr_edit_list_delete(el, vp, &local_pairs); /* middle */ TEST_CHECK(rcode == 0); vp = fr_pair_list_tail(&local_pairs); fr_assert(vp != NULL); - rcode = fr_edit_list_record(el, FR_EDIT_DELETE, vp, &local_pairs, NULL); /* tail */ + rcode = fr_edit_list_delete(el, vp, &local_pairs); /* tail */ TEST_CHECK(rcode == 0); talloc_free(el); @@ -325,13 +325,13 @@ static void test_pair_delete_multiple_abort(void) el = fr_edit_list_alloc(NULL); fr_assert(el != NULL); - rcode = fr_edit_list_record(el, FR_EDIT_DELETE, vp, &local_pairs, NULL); /* middle */ + rcode = fr_edit_list_delete(el, vp, &local_pairs); /* middle */ TEST_CHECK(rcode == 0); vp = fr_pair_list_tail(&local_pairs); fr_assert(vp != NULL); - rcode = fr_edit_list_record(el, FR_EDIT_DELETE, vp, &local_pairs, NULL); /* tail */ + rcode = fr_edit_list_delete(el, vp, &local_pairs); /* tail */ TEST_CHECK(rcode == 0); count = fr_pair_list_len(&local_pairs); @@ -372,7 +372,7 @@ static void test_pair_edit_value(void) el = fr_edit_list_alloc(NULL); fr_assert(el != NULL); - rcode = fr_edit_list_record(el, FR_EDIT_VALUE, vp, NULL, NULL); + rcode = fr_edit_list_record(el, vp); TEST_CHECK(rcode == 0); TEST_CHECK(vp->vp_uint32 == 0); @@ -406,7 +406,7 @@ static void test_pair_edit_value_abort(void) el = fr_edit_list_alloc(NULL); fr_assert(el != NULL); - rcode = fr_edit_list_record(el, FR_EDIT_VALUE, vp, NULL, NULL); + rcode = fr_edit_list_record(el, vp); TEST_CHECK(rcode == 0); TEST_CHECK(vp->vp_uint32 == 0);