]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
s/head/order_head/ s/entry/order in pair code
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 6 Oct 2021 22:15:16 +0000 (17:15 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 6 Oct 2021 22:32:35 +0000 (17:32 -0500)
This is to prepare for pair trees

src/lib/server/pairmove.c
src/lib/server/tmpl_eval.c
src/lib/unlang/xlat_pair.c
src/lib/util/pair.c
src/lib/util/pair.h
src/lib/util/pair_legacy.c

index 55bd9915673dfaba8c13495240020302bf9b87a8..6190fdf3ab325f30abfdc96ed396d2818d963580 100644 (file)
@@ -147,7 +147,7 @@ void radius_pairmove(request_t *request, fr_pair_list_t *to, fr_pair_list_t *fro
                                RDEBUG4("::: OVERWRITING %s FROM %d TO %d",
                                       to_vp->da->name, i, j);
                                fr_pair_remove(from, from_vp);
-                               vp = fr_dlist_replace(&to->head, to_vp, from_vp);
+                               vp = fr_dlist_replace(&to->order, to_vp, from_vp);
                                talloc_free(vp);
                                from_vp = NULL;
                                edited[j] = true;
@@ -228,7 +228,7 @@ void radius_pairmove(request_t *request, fr_pair_list_t *to, fr_pair_list_t *fro
                                                RDEBUG4("::: REPLACING %s FROM %d TO %d",
                                                       from_vp->da->name, i, j);
                                                fr_pair_remove(from, from_vp);
-                                               vp = fr_dlist_replace(&to->head, to_vp, from_vp);
+                                               vp = fr_dlist_replace(&to->order, to_vp, from_vp);
                                                talloc_free(vp);
                                                from_vp = NULL;
                                                edited[j] = true;
@@ -241,7 +241,7 @@ void radius_pairmove(request_t *request, fr_pair_list_t *to, fr_pair_list_t *fro
                                                RDEBUG4("::: REPLACING %s FROM %d TO %d",
                                                       from_vp->da->name, i, j);
                                                fr_pair_remove(from, from_vp);
-                                               vp = fr_dlist_replace(&to->head, to_vp, from_vp);
+                                               vp = fr_dlist_replace(&to->order, to_vp, from_vp);
                                                talloc_free(vp);
                                                from_vp = NULL;
                                                edited[j] = true;
index 8b1f54def8edea5a22d8097cc1ecd1c3c8096cb1..0d5898fc7e25b3846f06bf1f87c884b1e4543552 100644 (file)
@@ -1021,7 +1021,7 @@ static void *_tmpl_cursor_next(fr_dlist_head_t *list, void *curr, void *uctx)
                                list_head = &vp->vp_group;
                                _tmpl_pair_cursor_init(vp, list_head, ar, cc);
                                curr = fr_pair_list_head(list_head);
-                               list = &list_head->head;
+                               list = &list_head->order;
                                continue;
                        }
 
@@ -1501,7 +1501,7 @@ int tmpl_extents_find(TALLOC_CTX *ctx,
 
                list_ctx = ns->list_ctx;
                ar = ns->ar;
-               curr = _tmpl_cursor_eval(&list_head->head, curr, &cc);
+               curr = _tmpl_cursor_eval(&list_head->order, curr, &cc);
                if (!curr) {
                        /*
                         *      References extend beyond current
index d7d127767980174876cc33d62d6ac14a4dc0e489..14c5aa49a24f2a1dae275e40b307c1a6a94f9cdc 100644 (file)
@@ -135,7 +135,7 @@ int fr_pair_decode_value_box_list(TALLOC_CTX *ctx, fr_dcursor_t *out,
                }
        }
 
-       decoded = fr_dlist_num_elements(&head.head);
+       decoded = fr_pair_list_len(&head);
 
        fr_dcursor_init(&cursor, &head);
        fr_dcursor_merge(out, &cursor);
index d7104d9b6b3cff7c51fdf807874ac63cfd6f2043..9c9d3402d026caa57329bb2b5692935177762719 100644 (file)
@@ -40,7 +40,13 @@ RCSID("$Id$")
  */
 void fr_pair_list_init(fr_pair_list_t *list)
 {
-       fr_dlist_talloc_init(&list->head, fr_pair_t, entry);
+       /*
+        *      Initialises the order list.  This
+        *      maintains the overall order of attributes
+        *      in the list and allows us to iterate over
+        *      all of them.
+        */
+       fr_dlist_talloc_init(&list->order, fr_pair_t, order_entry);
 }
 
 /** Free a fr_pair_t
@@ -118,12 +124,16 @@ fr_pair_t *fr_pair_alloc_null(TALLOC_CTX *ctx)
                return NULL;
        }
 
-       vp->op = T_OP_EQ;
-       vp->type = VT_NONE;
-       fr_dlist_entry_init(&vp->entry);
+       fr_dlist_entry_init(&vp->order_entry);
 
        talloc_set_destructor(vp, _fr_pair_free);
 
+       /*
+        *      Legacy cruft
+        */
+       vp->op = T_OP_EQ;
+       vp->type = VT_NONE;
+
        return vp;
 }
 
@@ -151,9 +161,6 @@ fr_pair_t *fr_pair_root_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
                return NULL;
        }
 
-       vp->op = T_OP_EQ;
-       vp->type = VT_NONE;
-
        if (unlikely(da->flags.is_unknown)) {
                fr_strerror_const("Root attribute cannot be unknown");
                return NULL;
@@ -364,7 +371,7 @@ int fr_pair_steal(TALLOC_CTX *ctx, fr_pair_t *vp)
  */
 int fr_pair_steal_append(TALLOC_CTX *list_ctx, fr_pair_list_t *list, fr_pair_t *vp)
 {
-       if (fr_dlist_entry_in_list(&vp->entry)) {
+       if (fr_dlist_entry_in_list(&vp->order_entry)) {
                fr_strerror_printf("Pair %pV is a list member, cannot be moved", vp);
                return -1;
        }
@@ -387,7 +394,7 @@ int fr_pair_steal_append(TALLOC_CTX *list_ctx, fr_pair_list_t *list, fr_pair_t *
  */
 int fr_pair_steal_prepend(TALLOC_CTX *list_ctx, fr_pair_list_t *list, fr_pair_t *vp)
 {
-       if (fr_dlist_entry_in_list(&vp->entry)) {
+       if (fr_dlist_entry_in_list(&vp->order_entry)) {
                fr_strerror_printf("Pair %pV is a list member, cannot be moved", vp);
                return -1;
        }
@@ -407,7 +414,7 @@ int fr_pair_steal_prepend(TALLOC_CTX *list_ctx, fr_pair_list_t *list, fr_pair_t
  */
 void fr_pair_list_free(fr_pair_list_t *list)
 {
-       fr_dlist_talloc_free(&list->head);
+       fr_dlist_talloc_free(&list->order);
 }
 
 /** Is a valuepair list empty
@@ -419,7 +426,7 @@ void fr_pair_list_free(fr_pair_list_t *list)
  */
 bool fr_pair_list_empty(fr_pair_list_t const *list)
 {
-       return fr_dlist_empty(&list->head);
+       return fr_dlist_empty(&list->order);
 }
 
 /** Mark malformed or unrecognised attributed as unknown
@@ -512,7 +519,7 @@ unsigned int fr_pair_count_by_da(fr_pair_list_t const *list, fr_dict_attr_t cons
        fr_pair_t       *vp = NULL;
        unsigned int    count = 0;
 
-       if (fr_dlist_empty(&list->head)) return 0;
+       if (fr_dlist_empty(&list->order)) return 0;
 
        while ((vp = fr_pair_list_next(list, vp))) if (da == vp->da) count++;
 
@@ -534,7 +541,7 @@ fr_pair_t *fr_pair_find_by_da(fr_pair_list_t const *list, fr_dict_attr_t const *
 {
        fr_pair_t       *vp = NULL;
 
-       if (fr_dlist_empty(&list->head)) return NULL;
+       if (fr_dlist_empty(&list->order)) return NULL;
 
        LIST_VERIFY(list);
 
@@ -587,7 +594,7 @@ fr_pair_t *fr_pair_find_by_child_num(fr_pair_list_t *list, fr_dict_attr_t const
        fr_pair_t               *vp;
 
        /* List head may be NULL if it contains no VPs */
-       if (fr_dlist_empty(&list->head)) return NULL;
+       if (fr_dlist_empty(&list->order)) return NULL;
 
        LIST_VERIFY(list);
 
@@ -636,7 +643,7 @@ fr_pair_list_t *fr_pair_children(fr_pair_t *vp)
  */
 void *fr_pair_list_head(fr_pair_list_t const *list)
 {
-       return fr_dlist_head(&list->head);
+       return fr_dlist_head(&list->order);
 }
 
 /** Get the next item in a valuepair list after a specific entry
@@ -650,7 +657,7 @@ void *fr_pair_list_head(fr_pair_list_t const *list)
  */
 void *fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item)
 {
-       return fr_dlist_next(&list->head, item);
+       return fr_dlist_next(&list->order, item);
 }
 
 /** Get the previous item in a valuepair list before a specific entry
@@ -663,7 +670,7 @@ void *fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item)
  */
 void *fr_pair_list_prev(fr_pair_list_t const *list, fr_pair_t const *item)
 {
-       return fr_dlist_prev(&list->head, item);
+       return fr_dlist_prev(&list->order, item);
 }
 
 /** Get the tail of a valuepair list
@@ -676,7 +683,7 @@ void *fr_pair_list_prev(fr_pair_list_t const *list, fr_pair_t const *item)
  */
 void *fr_pair_list_tail(fr_pair_list_t const *list)
 {
-       return fr_dlist_tail(&list->head);
+       return fr_dlist_tail(&list->order);
 }
 
 /** Add a VP to the start of the list.
@@ -693,12 +700,12 @@ int fr_pair_prepend(fr_pair_list_t *list, fr_pair_t *to_add)
 {
        VP_VERIFY(to_add);
 
-       if (fr_dlist_entry_in_list(&to_add->entry)) {
+       if (fr_dlist_entry_in_list(&to_add->order_entry)) {
                fr_strerror_printf("Pair %pV already inserted into list", to_add);
                return -1;
        }
 
-       fr_dlist_insert_head(&list->head, to_add);
+       fr_dlist_insert_head(&list->order, to_add);
 
        return 0;
 }
@@ -717,12 +724,12 @@ int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
 {
        VP_VERIFY(to_add);
 
-       if (fr_dlist_entry_in_list(&to_add->entry)) {
+       if (fr_dlist_entry_in_list(&to_add->order_entry)) {
                fr_strerror_printf("Pair %pV already inserted into list", to_add);
                return -1;
        }
 
-       fr_dlist_insert_tail(&list->head, to_add);
+       fr_dlist_insert_tail(&list->order, to_add);
 
        return 0;
 }
@@ -744,7 +751,7 @@ void fr_pair_replace(fr_pair_list_t *list, fr_pair_t *replace)
 
        VP_VERIFY(replace);
 
-       if (fr_dlist_empty(&list->head)) {
+       if (fr_dlist_empty(&list->order)) {
                fr_pair_append(list, replace);
                return;
        }
@@ -762,7 +769,7 @@ void fr_pair_replace(fr_pair_list_t *list, fr_pair_t *replace)
                 *      and return.
                 */
                if (i->da == replace->da) {
-                       i = fr_dlist_replace(&list->head, i, replace);
+                       i = fr_dlist_replace(&list->order, i, replace);
                        talloc_free(i);
                        return;
                }
@@ -930,7 +937,7 @@ fr_pair_t *fr_pair_remove(fr_pair_list_t *list, fr_pair_t *vp)
        fr_pair_t *prev;
 
        prev = fr_pair_list_prev(list, vp);
-       fr_dlist_remove(&list->head, vp);
+       fr_dlist_remove(&list->order, vp);
 
        return prev;
 }
@@ -946,7 +953,7 @@ fr_pair_t *fr_pair_delete(fr_pair_list_t *list, fr_pair_t *vp)
        fr_pair_t *prev;
 
        prev = fr_pair_list_prev(list, vp);
-       fr_dlist_remove(&list->head, vp);
+       fr_dlist_remove(&list->order, vp);
        talloc_free(vp);
 
        return prev;
@@ -1183,7 +1190,7 @@ int fr_pair_list_cmp(fr_pair_list_t const *a, fr_pair_list_t const *b)
  */
 void fr_pair_list_sort(fr_pair_list_t *list, fr_cmp_t cmp)
 {
-       fr_dlist_sort(&list->head, cmp);
+       fr_dlist_sort(&list->order, cmp);
 }
 
 /** Write an error to the library errorbuff detailing the mismatch
@@ -1242,7 +1249,7 @@ bool fr_pair_validate(fr_pair_t const *failed[2], fr_pair_list_t *filter, fr_pai
 {
        fr_pair_t *check, *match;
 
-       if (fr_dlist_empty(&filter->head) && fr_dlist_empty(&list->head)) {
+       if (fr_dlist_empty(&filter->order) && fr_dlist_empty(&list->order)) {
                return true;
        }
 
@@ -1317,7 +1324,7 @@ bool fr_pair_validate_relaxed(fr_pair_t const *failed[2], fr_pair_list_t *filter
 {
        fr_pair_t *check, *last_check = NULL, *match = NULL;
 
-       if (fr_dlist_empty(&filter->head) && fr_dlist_empty(&list->head)) {
+       if (fr_dlist_empty(&filter->order) && fr_dlist_empty(&list->order)) {
                return true;
        }
 
@@ -1520,7 +1527,7 @@ int fr_pair_list_copy_by_ancestor(TALLOC_CTX *ctx, fr_pair_list_t *to,
                fr_pair_append(&tmp_list, new_vp);
        }
 
-       fr_dlist_move(&to->head, &tmp_list.head);
+       fr_dlist_move(&to->order, &tmp_list.order);
 
        return cnt;
 }
@@ -1558,7 +1565,7 @@ int fr_pair_sublist_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t con
                fr_pair_append(&tmp_list, new_vp);
        }
 
-       fr_dlist_move(&to->head, &tmp_list.head);
+       fr_dlist_move(&to->order, &tmp_list.order);
 
        return cnt;
 }
@@ -1577,9 +1584,9 @@ void fr_pair_value_clear(fr_pair_t *vp)
                break;
 
        case FR_TYPE_STRUCTURAL:
-               if (!fr_dlist_empty(&vp->vp_group.head)) return;
+               if (!fr_dlist_empty(&vp->vp_group.order)) return;
 
-               while ((child = fr_dlist_pop_tail(&vp->vp_group.head))) {
+               while ((child = fr_dlist_pop_tail(&vp->vp_group.order))) {
                        fr_pair_value_clear(child);
                        talloc_free(child);
                }
@@ -2548,7 +2555,7 @@ void fr_pair_list_afrom_box(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t cons
  */
 void fr_pair_list_append(fr_pair_list_t *dst, fr_pair_list_t *src)
 {
-       fr_dlist_move(&dst->head, &src->head);
+       fr_dlist_move(&dst->order, &src->order);
 }
 
 /** Move a list of fr_pair_t from a temporary list to the head of a destination list
@@ -2558,7 +2565,7 @@ void fr_pair_list_append(fr_pair_list_t *dst, fr_pair_list_t *src)
  */
 void fr_pair_list_prepend(fr_pair_list_t *dst, fr_pair_list_t *src)
 {
-       fr_dlist_move_head(&dst->head, &src->head);
+       fr_dlist_move_head(&dst->order, &src->order);
 }
 
 /** Evaluation function for matching if vp matches a given da
@@ -2585,5 +2592,5 @@ bool fr_pair_matches_da(void const *item, void const *uctx)
  */
 size_t fr_pair_list_len(fr_pair_list_t const *list)
 {
-       return list->head.num_elements;
+       return fr_dlist_num_elements(&list->order);
 }
index 79c72fcc588a01f6e4181898d57324d8804ff171..5bd043c5cfb1a7655bf7bd99aa26a949dcc351a5 100644 (file)
@@ -63,7 +63,7 @@ typedef enum value_type {
 typedef struct value_pair_s fr_pair_t;
 
 typedef struct {
-        fr_dlist_head_t head;
+        fr_dlist_head_t                order;                          //!< Maintains the relative order of pairs in a list.
 } fr_pair_list_t;
 
 /** Stores an attribute, a value and various bits of other data
@@ -74,18 +74,13 @@ typedef struct {
  */
 struct value_pair_s {
        fr_dict_attr_t const    *da;                            //!< Dictionary attribute defines the attribute
-                                                               //!< number, vendor and type of the attribute.
+                                                               //!< number, vendor and type of the pair.
 
-       fr_dlist_t              entry;                          //!< dlist entry pointers
+       fr_dlist_t              order_entry;                    //!< Entry to maintain relative order within a list
+                                                               ///< of pairs.  This ensures pairs within the list
+                                                               ///< are encoded in the same order as they were
+                                                               ///< received or inserted.
 
-       /*
-        *      Legacy stuff that needs to die.
-        */
-       struct {
-               fr_token_t              op;                     //!< Operator to use when moving or inserting
-                                                               //!< valuepair into a list.
-               char const              *xlat;                  //!< Source string for xlat expansion.
-       };
 
        value_type_t            type;                           //!< Type of pointer in value union.
 
@@ -96,6 +91,15 @@ struct value_pair_s {
                fr_value_box_t          data;                   //!< The value of this pair.
                fr_pair_list_t          children;               //!< Nested attributes of this pair.
        };
+
+       /*
+        *      Legacy stuff that needs to die.
+        */
+       struct {
+               fr_token_t              op;                     //!< Operator to use when moving or inserting
+                                                               //!< valuepair into a list.
+               char const              *xlat;                  //!< Source string for xlat expansion.
+       };
 };
 
 /** A fr_pair_t in string format.
@@ -162,7 +166,7 @@ void fr_pair_list_init(fr_pair_list_t *head);
  */
 #define fr_pair_list_set_head(_list, _vp) (_list = &_vp)
 
-#define fr_pair_list_from_dcursor(_cursor) (fr_pair_list_t *) (((uint8_t *) (_cursor->dlist)) - offsetof(fr_pair_list_t, head))
+#define fr_pair_list_from_dcursor(_cursor) (fr_pair_list_t *) (((uint8_t *) (_cursor->dlist)) - offsetof(fr_pair_list_t, order))
 
 /* Allocation and management */
 fr_pair_t      *fr_pair_alloc_null(TALLOC_CTX *ctx) CC_HINT(warn_unused_result);
@@ -211,7 +215,7 @@ bool                fr_pair_matches_da(void const *item, void const *uctx);
 static inline fr_pair_t *fr_dcursor_iter_by_da_init(fr_dcursor_t *cursor,
                                                    fr_pair_list_t *list, fr_dict_attr_t const *da)
 {
-       return fr_dcursor_talloc_iter_init(cursor, &list->head, fr_pair_iter_next_by_da, da, fr_pair_t);
+       return fr_dcursor_talloc_iter_init(cursor, &list->order, fr_pair_iter_next_by_da, da, fr_pair_t);
 }
 
 /** Initialise a cursor that will return only attributes descended from the specified #fr_dict_attr_t
@@ -226,7 +230,7 @@ static inline fr_pair_t *fr_dcursor_iter_by_da_init(fr_dcursor_t *cursor,
 static inline fr_pair_t *fr_dcursor_iter_by_ancestor_init(fr_dcursor_t *cursor,
                                                          fr_pair_list_t *list, fr_dict_attr_t const *da)
 {
-       return fr_dcursor_talloc_iter_init(cursor, &list->head, fr_pair_iter_next_by_ancestor, da, fr_pair_t);
+       return fr_dcursor_talloc_iter_init(cursor, &list->order, fr_pair_iter_next_by_ancestor, da, fr_pair_t);
 }
 
 /** @hidecallergraph */
index cdcaf20381a4b99fb7e69c81853ffb25eaf6df65..ef02b6683cafd3c91dcedc9c7d3e5f0baacaba14 100644 (file)
@@ -670,7 +670,7 @@ int fr_pair_list_afrom_file(TALLOC_CTX *ctx, fr_dict_t const *dict, fr_pair_list
                 *      attributes on a particular line, but only if
                 *      it's comments.
                 */
-               if (fr_dlist_empty(&tmp_list.head)) {
+               if (fr_dlist_empty(&tmp_list.order)) {
                        if (last_token == T_EOL) break;
 
                        /*