*/
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
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;
}
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;
*/
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;
}
*/
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;
}
*/
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
*/
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
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++;
{
fr_pair_t *vp = NULL;
- if (fr_dlist_empty(&list->head)) return NULL;
+ if (fr_dlist_empty(&list->order)) return NULL;
LIST_VERIFY(list);
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);
*/
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
*/
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
*/
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
*/
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.
{
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;
}
{
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;
}
VP_VERIFY(replace);
- if (fr_dlist_empty(&list->head)) {
+ if (fr_dlist_empty(&list->order)) {
fr_pair_append(list, replace);
return;
}
* 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;
}
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;
}
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;
*/
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
{
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;
}
{
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;
}
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;
}
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;
}
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);
}
*/
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
*/
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
*/
size_t fr_pair_list_len(fr_pair_list_t const *list)
{
- return list->head.num_elements;
+ return fr_dlist_num_elements(&list->order);
}
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
*/
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.
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.
*/
#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);
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
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 */