The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
pair_inline.c
Go to the documentation of this file.
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15  */
16 
17 /** AVP privately inlineable manipulation and search API
18  *
19  * @file src/lib/util/pair_inline.c
20  *
21  * @copyright 2022 Arran Cudbard-Bell <a.cudbardb@freeradius.org>
22  */
23 #ifndef _PAIR_INLINE
24 RCSID("$Id: 3f7a03fab3e0988d127df2c3c304ade0e06ae67f $")
25 # define _PAIR_PRIVATE 1
26 # include <freeradius-devel/util/pair.h>
27 # include <freeradius-devel/util/tlist.h>
28 # define _INLINE
29 FR_TLIST_FUNCS(fr_pair_order_list, fr_pair_t, order_entry)
30 #else
31 # define _INLINE CC_HINT(always_inline) static inline
32 #endif
33 
34 /** Get the head of a valuepair list
35  *
36  * @param[in] list to return the head of
37  *
38  * @return
39  * - NULL if the list is empty
40  * - pointer to the first item in the list.
41  * @hidecallergraph
42  */
44 {
45  return fr_pair_order_list_head(&list->order);
46 }
47 
48 /** Get the tail of a valuepair list
49  *
50  * @param[in] list to return the tail of
51  *
52  * @return
53  * - NULL if the list is empty
54  * - pointer to the last item in the list.
55  */
57 {
58  return fr_pair_order_list_tail(&list->order);
59 }
60 
61 /** Get the next item in a valuepair list after a specific entry
62  *
63  * @param[in] list to walk
64  * @param[in] item whose "next" item to return
65  * @return
66  * - NULL if the end of the list has been reached
67  * - pointer to the next item
68  * @hidecallergraph
69  */
71 {
72  return fr_pair_order_list_next(&list->order, item);
73 }
74 
75 /** Get the previous item in a valuepair list before a specific entry
76  *
77  * @param[in] list to walk
78  * @param[in] item whose "prev" item to return
79  * @return
80  * - NULL if the head of the list has been reached
81  * - pointer to the previous item
82  */
84 {
85  return fr_pair_order_list_prev(&list->order, item);
86 }
87 
88 /** Remove fr_pair_t from a list without freeing
89  *
90  * @param[in] list of value pairs to remove VP from.
91  * @param[in] vp to remove
92  * @return previous item in the list to the one being removed.
93  */
95 {
96  /*
97  * This check is commented out because it fails for
98  * update sections, things really don't work right :(
99  */
100 #if 0
101  fr_assert(fr_pair_order_list_in_a_list(vp));
102  fr_assert(list == fr_pair_parent_list(vp));
103  list->verified = false;
104 #endif
105 
106  return fr_pair_order_list_remove(&list->order, vp);
107 }
108 
109 /** Free memory used by a valuepair list.
110  *
111  * @hidecallergraph
112  */
114 {
115  fr_pair_order_list_talloc_free(&list->order);
116 }
117 
118 /** Is a valuepair list empty
119  *
120  * @param[in] list to check
121  * @return true if empty
122  *
123  * @hidecallergraph
124  */
126 {
127  return fr_pair_order_list_empty(&list->order);
128 }
129 
130 /** Sort a doubly linked list of fr_pair_ts using merge sort
131  *
132  * @note We use a merge sort (which is a stable sort), making this
133  * suitable for use on lists with things like EAP-Message
134  * fragments where the order of EAP-Message attributes needs to
135  * be maintained.
136  *
137  * @param[in,out] list head of dlinked fr_pair_ts to sort.
138  * @param[in] cmp to sort with
139  */
141 {
142  fr_pair_order_list_sort(&list->order, cmp);
143 }
144 
145 /** Get the length of a list of fr_pair_t
146  *
147  * @param[in] list to return the length of
148  *
149  * @return number of entries in the list
150  */
152 {
153  return fr_pair_order_list_num_elements(&list->order);
154 }
155 
156 /** Get the dlist head from a pair list
157  *
158  * @param[in] list to get the head from
159  *
160  * @return the pointer to the dlist within the pair list.
161  */
163 {
164  return fr_pair_order_list_dlist_head(&list->order);
165 }
166 
167 /** Get the pair list head from a dlist
168  *
169  * @param[in] list The order list from a pair list.
170  * @return The pair list head.
171  */
173 {
174  return (fr_pair_list_t *)((uintptr_t)list - offsetof(fr_pair_list_t, order));
175 }
176 
177 /** Appends a list of fr_pair_t from a temporary list to a destination list
178  *
179  * @param dst list to move pairs into
180  * @param src list from which to take pairs
181  */
183 {
184 #ifdef WITH_VERIFY_POINTER
185  dst->verified = false;
186 #endif
187  fr_pair_order_list_move(&dst->order, &src->order);
188 }
189 
190 /** Move a list of fr_pair_t from a temporary list to the head of a destination list
191  *
192  * @param dst list to move pairs into
193  * @param src from which to take pairs
194  */
196 {
197  fr_pair_order_list_move_head(&dst->order, &src->order);
198 }
#define RCSID(id)
Definition: build.h:481
return item
Definition: dcursor.h:553
Head of a doubly linked list.
Definition: dlist.h:51
int8_t(* fr_cmp_t)(void const *a, void const *b)
Definition: misc.h:38
fr_pair_list_t * fr_pair_parent_list(fr_pair_t const *vp)
Return a pointer to the parent pair list.
Definition: pair.c:927
_INLINE fr_pair_t * fr_pair_remove(fr_pair_list_t *list, fr_pair_t *vp)
Remove fr_pair_t from a list without freeing.
Definition: pair_inline.c:94
_INLINE size_t fr_pair_list_num_elements(fr_pair_list_t const *list)
Get the length of a list of fr_pair_t.
Definition: pair_inline.c:151
_INLINE void fr_pair_list_sort(fr_pair_list_t *list, fr_cmp_t cmp)
Sort a doubly linked list of fr_pair_ts using merge sort.
Definition: pair_inline.c:140
_INLINE void fr_pair_list_prepend(fr_pair_list_t *dst, fr_pair_list_t *src)
Move a list of fr_pair_t from a temporary list to the head of a destination list.
Definition: pair_inline.c:195
_INLINE fr_pair_t * fr_pair_list_tail(fr_pair_list_t const *list)
Get the tail of a valuepair list.
Definition: pair_inline.c:56
#define _INLINE
Definition: pair_inline.c:28
_INLINE fr_pair_t * fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item)
Get the next item in a valuepair list after a specific entry.
Definition: pair_inline.c:70
_INLINE fr_pair_list_t * fr_pair_list_from_dlist(fr_dlist_head_t const *list)
Get the pair list head from a dlist.
Definition: pair_inline.c:172
_INLINE fr_pair_t * fr_pair_list_head(fr_pair_list_t const *list)
Get the head of a valuepair list.
Definition: pair_inline.c:43
_INLINE void fr_pair_list_append(fr_pair_list_t *dst, fr_pair_list_t *src)
Appends a list of fr_pair_t from a temporary list to a destination list.
Definition: pair_inline.c:182
_INLINE void fr_pair_list_free(fr_pair_list_t *list)
Free memory used by a valuepair list.
Definition: pair_inline.c:113
_INLINE fr_pair_t * fr_pair_list_prev(fr_pair_list_t const *list, fr_pair_t const *item)
Get the previous item in a valuepair list before a specific entry.
Definition: pair_inline.c:83
_INLINE fr_dlist_head_t * fr_pair_list_to_dlist(fr_pair_list_t const *list)
Get the dlist head from a pair list.
Definition: pair_inline.c:162
_INLINE bool fr_pair_list_empty(fr_pair_list_t const *list)
Is a valuepair list empty.
Definition: pair_inline.c:125
fr_assert(0)
fr_pair_t * vp
Stores an attribute, a value and various bits of other data.
Definition: pair.h:68
#define FR_TLIST_FUNCS(_name, _element_type, _element_entry)
Define type specific wrapper functions for tlists.
Definition: tlist.h:790