The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
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
24RCSID("$Id: 27ee74efb7489e8069bf51597f7fc46d77ad14e0 $")
25# define _PAIR_PRIVATE 1
26# include <freeradius-devel/util/pair.h>
27# define _INLINE
28FR_TLIST_FUNCS(fr_pair_order_list, fr_pair_t, order_entry)
29#else
30# define _INLINE CC_HINT(always_inline) static inline
31#endif
32
33/** Get the head of a valuepair list
34 *
35 * @param[in] list to return the head of
36 *
37 * @return
38 * - NULL if the list is empty
39 * - pointer to the first item in the list.
40 * @hidecallergraph
41 */
43{
44 return fr_pair_order_list_head(&list->order);
45}
46
47/** Get the tail of a valuepair list
48 *
49 * @param[in] list to return the tail of
50 *
51 * @return
52 * - NULL if the list is empty
53 * - pointer to the last item in the list.
54 */
56{
57 return fr_pair_order_list_tail(&list->order);
58}
59
60/** Get the next item in a valuepair list after a specific entry
61 *
62 * @param[in] list to walk
63 * @param[in] item whose "next" item to return
64 * @return
65 * - NULL if the end of the list has been reached
66 * - pointer to the next item
67 * @hidecallergraph
68 */
70{
71 return fr_pair_order_list_next(&list->order, item);
72}
73
74/** Get the previous item in a valuepair list before a specific entry
75 *
76 * @param[in] list to walk
77 * @param[in] item whose "prev" item to return
78 * @return
79 * - NULL if the head of the list has been reached
80 * - pointer to the previous item
81 */
83{
84 return fr_pair_order_list_prev(&list->order, item);
85}
86
87/** Remove fr_pair_t from a list without freeing
88 *
89 * @param[in] list of value pairs to remove VP from.
90 * @param[in] vp to remove
91 * @return previous item in the list to the one being removed.
92 */
94{
95 /*
96 * This check is commented out because it fails for
97 * update sections, things really don't work right :(
98 */
99#if 0
100 fr_assert(fr_pair_order_list_in_a_list(vp));
102 list->verified = false;
103#endif
104
105 return fr_pair_order_list_remove(&list->order, vp);
106}
107
108/** Free memory used by a valuepair list.
109 *
110 * @hidecallergraph
111 */
113{
114 fr_pair_order_list_talloc_free(&list->order);
115}
116
117/** Is a valuepair list empty
118 *
119 * @param[in] list to check
120 * @return true if empty
121 *
122 * @hidecallergraph
123 */
125{
126 return fr_pair_order_list_empty(&list->order);
127}
128
129/** Sort a doubly linked list of fr_pair_ts using merge sort
130 *
131 * @note We use a merge sort (which is a stable sort), making this
132 * suitable for use on lists with things like EAP-Message
133 * fragments where the order of EAP-Message attributes needs to
134 * be maintained.
135 *
136 * @param[in,out] list head of dlinked fr_pair_ts to sort.
137 * @param[in] cmp to sort with
138 */
140{
141 fr_pair_order_list_sort(&list->order, cmp);
142}
143
144/** Get the length of a list of fr_pair_t
145 *
146 * @param[in] list to return the length of
147 *
148 * @return number of entries in the list
149 */
151{
152 return fr_pair_order_list_num_elements(&list->order);
153}
154
155/** Get the dlist head from a pair list
156 *
157 * @param[in] list to get the head from
158 *
159 * @return the pointer to the dlist within the pair list.
160 */
162{
163 return fr_pair_order_list_dlist_head(&list->order);
164}
165
166/** Get the pair list head from a dlist
167 *
168 * @param[in] list The order list from a pair list.
169 * @return The pair list head.
170 */
172{
173 return (fr_pair_list_t *)((uintptr_t)list - offsetof(fr_pair_list_t, order));
174}
175
176/** Appends a list of fr_pair_t from a temporary list to a destination list
177 *
178 * @param dst list to move pairs into
179 * @param src list from which to take pairs
180 */
182{
183#ifdef WITH_VERIFY_POINTER
184 dst->verified = false;
185#endif
186 fr_pair_order_list_move(&dst->order, &src->order);
187}
188
189/** Move a list of fr_pair_t from a temporary list to the head of a destination list
190 *
191 * @param dst list to move pairs into
192 * @param src from which to take pairs
193 */
195{
196 fr_pair_order_list_move_head(&dst->order, &src->order);
197}
#define RCSID(id)
Definition build.h:485
Head of a doubly linked list.
Definition dlist.h:51
static void * item(fr_lst_t const *lst, fr_lst_index_t idx)
Definition lst.c:122
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:929
_INLINE size_t fr_pair_list_num_elements(fr_pair_list_t const *list)
Get the length of a list of fr_pair_t.
_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.
_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:42
_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.
_INLINE fr_pair_list_t * fr_pair_list_from_dlist(fr_dlist_head_t const *list)
Get the pair list head from a dlist.
_INLINE fr_dlist_head_t * fr_pair_list_to_dlist(fr_pair_list_t const *list)
Get the dlist head from a pair list.
#define _INLINE
Definition pair_inline.c:27
_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.
_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:69
_INLINE void fr_pair_list_free(fr_pair_list_t *list)
Free memory used by a valuepair list.
_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:93
_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:82
_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:55
_INLINE bool fr_pair_list_empty(fr_pair_list_t const *list)
Is a valuepair list empty.
#define fr_assert(_expr)
Definition rad_assert.h:38
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