Coverage Report

Created: 2026-10-18 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/freeradius-server/src/freeradius-devel/util/pair_inline.c
Line
Count
Source
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: a36dd0040e1a014769c7188a29129ec978150b2c $")
25
#  define _PAIR_PRIVATE 1
26
#  include <freeradius-devel/util/pair.h>
27
#  define _INLINE
28
FR_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
 */
42
_INLINE fr_pair_t *fr_pair_list_head(fr_pair_list_t const *list)
43
289k
{
44
289k
  return fr_pair_order_list_head(&list->order);
45
289k
}
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
 */
55
_INLINE fr_pair_t *fr_pair_list_tail(fr_pair_list_t const *list)
56
0
{
57
0
  return fr_pair_order_list_tail(&list->order);
58
0
}
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
 */
69
_INLINE fr_pair_t *fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item)
70
4.78M
{
71
4.78M
  return fr_pair_order_list_next(&list->order, item);
72
4.78M
}
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
 */
82
_INLINE fr_pair_t *fr_pair_list_prev(fr_pair_list_t const *list, fr_pair_t const *item)
83
0
{
84
0
  return fr_pair_order_list_prev(&list->order, item);
85
0
}
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
 */
93
_INLINE fr_pair_t *fr_pair_remove(fr_pair_list_t *list, fr_pair_t *vp)
94
2.58k
{
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));
101
  fr_assert(list == fr_pair_parent_list(vp));
102
  list->verified = false;
103
#endif
104
105
2.58k
  return fr_pair_order_list_remove(&list->order, vp);
106
2.58k
}
107
108
/** Free memory used by a valuepair list.
109
 *
110
 * @hidecallergraph
111
 */
112
_INLINE void fr_pair_list_free(fr_pair_list_t *list)
113
263k
{
114
263k
  fr_pair_order_list_talloc_free(&list->order);
115
263k
}
116
117
/** Is a valuepair list empty
118
 *
119
 * @param[in] list to check
120
 * @return true if empty
121
 *
122
 * @hidecallergraph
123
 */
124
_INLINE bool fr_pair_list_empty(fr_pair_list_t const *list)
125
337k
{
126
337k
  return fr_pair_order_list_empty(&list->order);
127
337k
}
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
 * @return
139
 *  - 0 on success.
140
 *  - -1 on comparator error, retrieve the error with fr_strerror.  The list is
141
 *    intact but its order is undefined.
142
 */
143
_INLINE int fr_pair_list_sort(fr_pair_list_t *list, fr_cmp_t cmp)
144
0
{
145
0
  return fr_pair_order_list_sort(&list->order, cmp);
146
0
}
147
148
/** Get the length of a list of fr_pair_t
149
 *
150
 * @param[in] list to return the length of
151
 *
152
 * @return number of entries in the list
153
 */
154
_INLINE size_t fr_pair_list_num_elements(fr_pair_list_t const *list)
155
0
{
156
0
  return fr_pair_order_list_num_elements(&list->order);
157
0
}
158
159
/** Appends a list of fr_pair_t from a temporary list to a destination list
160
 *
161
 * @param dst list to move pairs into
162
 * @param src list from which to take pairs
163
 */
164
_INLINE void fr_pair_list_append(fr_pair_list_t *dst, fr_pair_list_t *src)
165
0
{
166
#ifdef WITH_VERIFY_POINTER
167
  dst->verified = false;
168
#endif
169
0
  fr_pair_order_list_move(&dst->order, &src->order);
170
0
}
171
172
/** Move a list of fr_pair_t from a temporary list to the head of a destination list
173
 *
174
 * @param dst list to move pairs into
175
 * @param src from which to take pairs
176
 */
177
_INLINE void fr_pair_list_prepend(fr_pair_list_t *dst, fr_pair_list_t *src)
178
0
{
179
0
  fr_pair_order_list_move_head(&dst->order, &src->order);
180
0
}