The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
pair.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/** AVP manipulation and search API
19 *
20 * @file src/lib/util/pair.h
21 *
22 * @copyright 2020 The FreeRADIUS server project
23 */
24RCSIDH(dpair_h, "$Id: 80f696da0cade9d84521a53173249276d8cd1c6e $")
25
26#include <freeradius-devel/build.h>
27#include <freeradius-devel/missing.h>
28#include <freeradius-devel/util/dcursor.h>
29#include <freeradius-devel/util/value.h>
30#include <freeradius-devel/util/tlist.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/*
37 * Allow public and private versions of the same structures
38 */
39#ifdef _CONST
40# error _CONST can only be defined in the local header
41#endif
42#ifndef _PAIR_PRIVATE
43# define _CONST const
44#else
45# define _CONST
46#endif
47
48typedef struct value_pair_s fr_pair_t;
49
50FR_TLIST_TYPES(fr_pair_order_list)
51
52typedef struct pair_list_s {
53 FR_TLIST_HEAD(fr_pair_order_list) order; //!< Maintains the relative order of pairs in a list.
54
55 bool _CONST is_child; //!< is a child of a VP
56
57#ifdef WITH_VERIFY_PTR
58 unsigned int verified : 1; //!< hack to avoid O(N^3) issues
59#endif
61
62/** Stores an attribute, a value and various bits of other data
63 *
64 * fr_pair_ts are the main data structure used in the server
65 *
66 * They also specify what behaviour should be used when the attribute is merged into a new list/tree.
67 */
69 fr_dict_attr_t const * _CONST da; //!< Dictionary attribute defines the attribute
70 //!< number, vendor and type of the pair.
71 ///< Note: This should not be modified outside
72 ///< of pair.c except via #fr_pair_reinit_from_da.
73
74 FR_TLIST_ENTRY(fr_pair_order_list) _CONST order_entry; //!< Entry to maintain relative order within a list
75 ///< of pairs. This ensures pairs within the list
76 ///< are encoded in the same order as they were
77 ///< received or inserted.
78
79
80 /*
81 * Pairs can have children or data but not both.
82 */
83 union {
84 fr_value_box_t data; //!< The value of this pair.
85
86 struct {
87 /** Force children field to come _after_ the safety field in the fr_value_box_t
88 *
89 * This works no matter where type appears in fr_value_box_t, whereas just
90 * listing another fr_type_t field here does not.
91 *
92 * This hack allows the majority of the fr_pair_list_t to overlap with the
93 * fr_value_box_t which gives us much greater packing efficiency.
94 */
95 uint8_t pad[offsetof(fr_value_box_t, safety)];
96
97 fr_pair_list_t children; //!< Nested attributes of this pair.
98 };
99 };
100
101#ifdef WITH_VERIFY_PTR
102 bool verified; //!< whether or not this pair was verified
103#endif
104
105 /*
106 * Legacy stuff that needs to die.
107 */
108 struct {
109 fr_token_t op; //!< Operator to use when moving or inserting
110 };
111};
112
113#define vp_strvalue data.vb_strvalue
114#define vp_octets data.vb_octets
115#define vp_ptr data.datum.ptr //!< Either octets or strvalue
116#define vp_length data.vb_length
117
118#define vp_ipv4addr data.vb_ip.addr.v4.s_addr
119#define vp_ipv6addr data.vb_ip.addr.v6.s6_addr
120#define vp_ip data.vb_ip
121#define vp_ifid data.vb_ifid
122#define vp_ether data.vb_ether
123
124#define vp_bool data.datum.boolean
125#define vp_uint8 data.vb_uint8
126#define vp_uint16 data.vb_uint16
127#define vp_uint32 data.vb_uint32
128#define vp_uint64 data.vb_uint64
129
130#define vp_int8 data.vb_int8
131#define vp_int16 data.vb_int16
132#define vp_int32 data.vb_int32
133#define vp_int64 data.vb_int64
134
135#define vp_float32 data.vb_float32
136#define vp_float64 data.vb_float64
137
138#define vp_attr data.vb_attr
139
140#define vp_date data.vb_date
141#define vp_time_delta data.vb_time_delta
142
143#define vp_group children
144
145#define vp_size data.datum.size
146#define vp_filter data.datum.filter
147
148#define vp_type data.type
149#define vp_tainted data.tainted
150#define vp_immutable data.immutable
151#define vp_edit data.edit
152#define vp_raw da->flags.is_raw
153
154#define ATTRIBUTE_EQ(_x, _y) ((_x && _y) && (_x->da == _y->da))
155
156/** If WITH_VERIFY_PTR is defined, we perform runtime checks to ensure the fr_pair_t are sane
157 *
158 */
159#ifdef WITH_VERIFY_PTR
160void fr_pair_verify(char const *file, int line, fr_dict_attr_t const *parent,
161 fr_pair_list_t const *list, fr_pair_t const *vp, bool verify_values) CC_HINT(nonnull(5));
162
163void fr_pair_list_verify(char const *file, int line,
164 TALLOC_CTX const *expected, fr_pair_list_t const *list, bool verify_values) CC_HINT(nonnull(4));
165
166# define PAIR_VERIFY(_x) fr_pair_verify(__FILE__, __LINE__, NULL, NULL, _x, true)
167# define PAIR_VERIFY_WITH_LIST(_l, _x) fr_pair_verify(__FILE__, __LINE__, NULL, _l, _x, true)
168# define PAIR_LIST_VERIFY(_x) fr_pair_list_verify(__FILE__, __LINE__, NULL, _x, true)
169# define PAIR_LIST_VERIFY_WITH_CTX(_c, _x) fr_pair_list_verify(__FILE__, __LINE__, _c, _x, true)
170# define PAIR_VERIFY_WITH_PARENT_VP(_p, _x) fr_pair_verify(__FILE__, __LINE__, (_p)->da, &(_p)->vp_group, _x, true)
171# define PAIR_VERIFY_WITH_PARENT_DA(_p, _x) fr_pair_verify(__FILE__, __LINE__, _p, NULL, _x, true)
172
173/*
174 * On debug builds, various macros to ensure that the pair is marked up with the file and location of
175 * where it was allocated. Also have a wrapper for fr_pair_append(), so that before we put it into a
176 * list, we mark the pair with where it was allocated, and then also verify it.
177 */
178# define PAIR_ALLOCED(_x) do { (_x)->data.file = __FILE__; (_x)->data.line = __LINE__; } while (0)
179# define FR_PAIR_APPEND(_list, _x) do { PAIR_ALLOCED(_x); PAIR_VERIFY(_x); fr_pair_append(_list, _x); } while (0)
180#else
181DIAG_OFF(nonnull-compare)
182/** Wrapper function to defeat nonnull checks
183 *
184 * We may sprinkle PAIR_VERIFY and PAIR_LIST_VERIFY in functions which
185 * have their pair argument marked up as nonnull.
186 *
187 * This would usually generate errors when WITH_VERIFY_PTR is not
188 * defined, as the assert macros check for an arguments NULLness.
189 *
190 * This function wraps the assert but has nonnull-compare disabled
191 * meaning a warning won't be emitted.
192 */
193static inline bool fr_pair_nonnull_assert(fr_pair_t const *vp)
194{
195 return fr_cond_assert(vp);
196}
197
199{
201}
202DIAG_ON(nonnull-compare)
203
204/*
205 * Even if were building without WITH_VERIFY_PTR
206 * the pointer must not be NULL when these various macros are used
207 * so we can add some sneaky soft asserts.
208 */
209# define PAIR_VERIFY(_x) fr_pair_nonnull_assert(_x)
210# define PAIR_VERIFY_WITH_LIST(_l, _x) fr_pair_list_nonnull_assert(_l); \
211 fr_pair_nonnull_assert(_x)
212# define PAIR_LIST_VERIFY(_x) fr_pair_list_nonnull_assert(_x)
213# define PAIR_LIST_VERIFY_WITH_CTX(_c, _x) fr_pair_list_nonnull_assert(_x)
214# define PAIR_VERIFY_WITH_PARENT_VP(_p, _x) fr_pair_list_nonnull_assert(_p); \
215 fr_pair_list_nonnull_assert(_x)
216# define PAIR_VERIFY_WITH_PARENT_DA(_p, _x) fr_pair_list_nonnull_assert(_x)
217# define PAIR_ALLOCED(_x) fr_pair_nonnull_assert(_x)
218# define FR_PAIR_APPEND fr_pair_append
219#endif
220
221
222#ifdef TEST_CHECK
223/** Macro for use in acutest tests
224 */
225#define TEST_CHECK_PAIR(_got, _exp) \
226do { \
227 fr_pair_t const *_our_got = (_got); \
228 fr_pair_t const *_our_exp = (_exp); \
229 TEST_CHECK_(_our_exp == _our_got, "%s", #_got); \
230 if (_our_exp) { \
231 TEST_MSG("Expected pair : %s - %p (%s)", (_our_exp)->da->name, _our_exp, talloc_get_name(_our_exp)); \
232 } else { \
233 TEST_MSG("Expected pair : NULL"); \
234 } \
235 if (_our_got) { \
236 TEST_MSG("Got pair : %s - %p (%s)", (_our_got)->da->name, _our_got, talloc_get_name(_our_got)); \
237 } else { \
238 TEST_MSG("Got Pair : NULL"); \
239 } \
240} while(0)
241
242#define TEST_CHECK_PAIR_NEQ(_got, _neq) \
243do { \
244 fr_pair_t const *_our_got = (_got); \
245 fr_pair_t const *_our_neq = (_neq); \
246 TEST_CHECK_(_our_got != _our_neq, "%s", #_got); \
247 if (_our_neq) { \
248 TEST_MSG("Pair must not equal : %s - %p (%s)", (_our_neq)->da->name, _our_neq, talloc_get_name(_our_neq)); \
249 } else { \
250 TEST_MSG("Pair must not equal : NULL"); \
251 } \
252} while(0)
253#endif
254
255/*
256 * Helper macros for adding pairs to lists and assigning a value to them
257 */
258
259/** Check a pair's data type matches the DA data type
260 *
261 * @param[in] vp to check consistency of.
262 * @return
263 * - true for match
264 * - false for error
265 */
267{
268 if (vp->vp_type == vp->da->type) return true;
269
270 fr_strerror_printf("fr_pair_t attribute %p \"%s\" data type (%s) does not match da type (%s)",
271 vp->da, vp->da->name,
272 fr_table_str_by_value(fr_type_table, vp->vp_type, "invalid"),
273 fr_table_str_by_value(fr_type_table, vp->da->type, "invalid"));
274 return false;
275}
276
277/** Iterate over the contents of a #fr_pair_list_t
278 *
279 * The iteration variable can be safely removed from the list at each pass.
280 *
281 * @param[in] _list_head to iterate over.
282 * @param[in] _iter Name of iteration variable.
283 * Will be declared in the scope of the loop.
284 */
285#define fr_pair_list_foreach(_list_head, _iter) \
286 for (fr_pair_t *JOIN(_next,_iter), *_iter = fr_pair_list_head(_list_head); JOIN(_next,_iter) = fr_pair_list_next(_list_head, _iter), _iter != NULL; _iter = JOIN(_next,_iter))
287
288/** Iterate over the leaf nodes of a #fr_pair_list_t
289 *
290 * The iteration variable CANNOT be modified. This is a read-only operation.
291 *
292 * @param[in] _list_head to iterate over.
293 * @param[in] _iter Name of iteration variable.
294 * Will be declared in the scope of the loop.
295 */
296#define fr_pair_list_foreach_leaf(_list_head, _iter) \
297 for (fr_pair_t *_iter = fr_pair_list_iter_leaf(_list_head, NULL); _iter != NULL; _iter = fr_pair_list_iter_leaf(_list_head, _iter))
298
299/** Append a pair to a list, assigning its value.
300 *
301 * Version for simple C data types
302 *
303 * @param[in] _ctx to allocate the pair in
304 * @param[out] _vp the allocated pair
305 * @param[in] _list to append the pair to
306 * @param[in] _attr to use when creating pair
307 * @param[in] _val to assign to the pair
308 * @param[in] _tainted does the value come from a trusted source
309 */
310#define fr_pair_list_append_by_da(_ctx, _vp, _list, _attr, _val, _tainted) \
311do { \
312 _vp = NULL; \
313 if (fr_pair_append_by_da(_ctx, &_vp, _list, _attr) < 0) break; \
314 fr_value_box(&_vp->data, _val, _tainted); \
315 if (!vp_da_data_type_check(_vp)) { \
316 fr_pair_delete(_list, _vp); \
317 _vp = NULL; \
318 } \
319} while (0)
320
321/** Append a pair to a list, assigning its value.
322 *
323 * Version for char* and uint8_t*
324 *
325 * @param[in] _ctx to allocate the pair in
326 * @param[out] _vp the allocated pair
327 * @param[in] _list to append the pair to
328 * @param[in] _attr to use when creating pair
329 * @param[in] _val to assign to the pair
330 * @param[in] _len of value
331 * @param[in] _tainted does the value come from a trusted source
332 */
333#define fr_pair_list_append_by_da_len(_ctx, _vp, _list, _attr, _val, _len, _tainted) \
334do { \
335 _vp = NULL; \
336 if (fr_pair_append_by_da(_ctx, &_vp, _list, _attr) < 0) break; \
337 fr_value_box_len(_vp, &_vp->data, _val, _len, _tainted); \
338 if (!vp_da_data_type_check(_vp)) { \
339 fr_pair_delete(_list, _vp); \
340 _vp = NULL; \
341 } \
342} while (0)
343
344#define fr_pair_list_append_by_da_parent(_ctx, _vp, _list, _attr, _val, _tainted) \
345do { \
346 _vp = NULL; \
347 if (fr_pair_append_by_da_parent(_ctx, &_vp, _list, _attr) < 0) break; \
348 fr_value_box(&_vp->data, _val, _tainted); \
349 if (!vp_da_data_type_check(_vp)) { \
350 fr_pair_delete(_list, _vp); \
351 _vp = NULL; \
352 } \
353} while (0)
354
355#define fr_pair_list_append_by_da_parent_len(_ctx, _vp, _list, _attr, _val, _len, _tainted) \
356do { \
357 _vp = NULL; \
358 if (fr_pair_append_by_da_parent(_ctx, &_vp, _list, _attr) < 0) break; \
359 fr_value_box_len(_vp, &_vp->data, _val, _len, _tainted); \
360 if (!vp_da_data_type_check(_vp)) { \
361 fr_pair_delete(_list, _vp); \
362 _vp = NULL; \
363 } \
364} while (0)
365
366/** Prepend a pair to a list, assigning its value
367 *
368 * Version for simple C data types
369 *
370 * @param[in] _ctx to allocate the pair in
371 * @param[out] _vp the allocated pair
372 * @param[in] _list to prepend the pair to
373 * @param[in] _attr to use when creating pair
374 * @param[in] _val to assign to the pair
375 * @param[in] _tainted does the value come from a trusted source
376 */
377#define fr_pair_list_prepend_by_da(_ctx, _vp, _list, _attr, _val, _tainted) \
378do { \
379 _vp = NULL; \
380 if (fr_pair_prepend_by_da(_ctx, &_vp, _list, _attr) < 0) break; \
381 fr_value_box(&_vp->data, _val, _tainted); \
382 if (!vp_da_data_type_check(_vp)) { \
383 fr_pair_delete(_list, _vp); \
384 _vp = NULL; \
385 } \
386} while (0)
387
388/** Prepend a pair to a list, assigning its value.
389 *
390 * Version for char* and uint8_t*
391 *
392 * @param[in] _ctx to allocate the pair in
393 * @param[out] _vp the allocated pair
394 * @param[in] _list to prepend the pair to
395 * @param[in] _attr to use when creating pair
396 * @param[in] _val to assign to the pair
397 * @param[in] _len of value
398 * @param[in] _tainted does the value come from a trusted source
399 */
400#define fr_pair_list_prepend_by_da_len(_ctx, _vp, _list, _attr, _val, _len, _tainted) \
401do { \
402 _vp = NULL; \
403 if (fr_pair_prepend_by_da(_ctx, &_vp, _list, _attr) < 0) break; \
404 fr_value_box_len(_vp, &_vp->data, _val, _len, _tainted); \
405 if (!vp_da_data_type_check(_vp)) { \
406 fr_pair_delete(_list, _vp); \
407 _vp = NULL; \
408 } \
409} while (0)
410
411/** Replace a pair in a list, assigning its value
412 *
413 * Version for simple C data types.
414 * If the pair does not already exist, a new one is allocated.
415 *
416 * @param[out] _vp the allocated pair
417 * @param[in] _list to append the pair to
418 * @param[in] _attr to use when creating pair
419 * @param[in] _val to assign to the pair
420 * @param[in] _tainted does the value come from a trusted source
421 */
422#define fr_pair_list_replace_by_da(_vp, _list, _attr, _val, _tainted) \
423do { \
424 fr_pair_update_by_da_parent(fr_pair_list_parent(_list), &_vp, _attr); \
425 if (!_vp) break; \
426 fr_value_box(&_vp->data, _val, _tainted); \
427 if (!vp_da_data_type_check(_vp)) { \
428 fr_pair_delete(_list, _vp); \
429 _vp = NULL; \
430 } \
431} while (0)
432
433/** Replace a pair in a list, assigning its value
434 *
435 * Version for char* and uint8_t*
436 * If the pair does not already exist, a new one is allocated.
437 *
438 * @param[in] _ctx to allocate the pair in
439 * @param[out] _vp the allocated pair
440 * @param[in] _list to append the pair to
441 * @param[in] _attr to use when creating pair
442 * @param[in] _val to assign to the pair
443 * @param[in] _len of value
444 * @param[in] _tainted does the value come from a trusted source
445 */
446#define fr_pair_list_replace_by_da_len(_ctx, _vp, _list, _attr, _val, _len, _tainted) \
447do { \
448 fr_pair_t *oldvp = fr_pair_find_by_da(_list, NULL, _attr); \
449 fr_pair_list_append_by_da_len(_ctx, _vp, _list, _attr, _val, _len, _tainted); \
450 if (!vp_da_data_type_check(_vp)) { \
451 fr_pair_delete(_list, _vp); \
452 _vp = NULL; \
453 } \
454 if (!_vp) break; \
455 if (oldvp) fr_pair_delete(_list, oldvp); \
456} while (0)
457
458/* Initialisation */
459/** @hidecallergraph */
461
462void fr_pair_init_null(fr_pair_t *vp) CC_HINT(nonnull);
463
464/* Allocation and management */
465fr_pair_t *fr_pair_alloc_null(TALLOC_CTX *ctx) CC_HINT(warn_unused_result);
466
467fr_pair_list_t *fr_pair_list_alloc(TALLOC_CTX *ctx) CC_HINT(warn_unused_result);
468
469fr_pair_t *fr_pair_root_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da) CC_HINT(warn_unused_result) CC_HINT(nonnull(2));
470
471/** @hidecallergraph */
472fr_pair_t *fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da) CC_HINT(warn_unused_result) CC_HINT(nonnull(2));
473
475 CC_HINT(nonnull(2, 3));
476
477fr_pair_t *fr_pair_afrom_child_num(TALLOC_CTX *ctx, fr_dict_attr_t const *parent, unsigned int attr) CC_HINT(warn_unused_result);
478
479fr_pair_t *fr_pair_afrom_da_nested(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_attr_t const *da) CC_HINT(warn_unused_result) CC_HINT(nonnull(2,3));
480
481fr_pair_t *fr_pair_afrom_da_depth_nested(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_attr_t const *da, unsigned int start) CC_HINT(warn_unused_result) CC_HINT(nonnull(2,3));
482
483fr_pair_t *fr_pair_copy(TALLOC_CTX *ctx, fr_pair_t const *vp) CC_HINT(nonnull(2)) CC_HINT(warn_unused_result);
484
485int fr_pair_steal(TALLOC_CTX *ctx, fr_pair_t *vp) CC_HINT(nonnull);
486
487int fr_pair_steal_append(TALLOC_CTX *nctx, fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull);
488
489int fr_pair_steal_prepend(TALLOC_CTX *nctx, fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull);
490
491/* Searching and list modification */
492int fr_pair_raw_afrom_pair(fr_pair_t *vp, uint8_t const *data, size_t data_len) CC_HINT(nonnull);
493
494bool fr_pair_matches_da(void const *item, void const *uctx) CC_HINT(nonnull);
495
496/** @hidecallergraph */
497unsigned int fr_pair_count_by_da(fr_pair_list_t const *list, fr_dict_attr_t const *da)
498 CC_HINT(nonnull);
499
500/** @hidecallergraph */
502 fr_pair_t const *prev, fr_dict_attr_t const *da) CC_HINT(nonnull(1,3));
503
505 fr_dict_attr_t const *da, unsigned int idx) CC_HINT(nonnull);
506
508
510
512 fr_dict_attr_t const *parent, unsigned int attr,
513 unsigned int idx) CC_HINT(nonnull);
514
515/** @hidecallergraph */
516int fr_pair_append(fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull);
517
519
520int fr_pair_insert_after(fr_pair_list_t *list, fr_pair_t *pos, fr_pair_t *to_add) CC_HINT(nonnull(1,3));
521
522int fr_pair_insert_before(fr_pair_list_t *list, fr_pair_t *pos, fr_pair_t *to_add) CC_HINT(nonnull(1,3));
523
524void fr_pair_replace(fr_pair_list_t *list, fr_pair_t *to_replace, fr_pair_t *vp) CC_HINT(nonnull);
525
527 fr_dict_attr_t const *parent, unsigned int attr) CC_HINT(nonnull);
528
529int fr_pair_append_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list,
530 fr_dict_attr_t const *da) CC_HINT(nonnull(3,4));
531
532int fr_pair_prepend_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list,
533 fr_dict_attr_t const *da) CC_HINT(nonnull(3,4));
534
535int fr_pair_append_by_da_parent(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list,
536 fr_dict_attr_t const *da) CC_HINT(nonnull(3,4));
537
539 fr_dict_attr_t const *da) CC_HINT(nonnull(1,3));
540
541static inline CC_HINT(nonnull(3,4)) int fr_pair_find_or_append_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list,
542 fr_dict_attr_t const *da)
543{
544 fr_pair_t *vp;
545
546 vp = fr_pair_find_by_da(list, NULL, da);
547 if (vp) {
548 *out = vp;
549 return 0;
550 }
551
552 return fr_pair_append_by_da(ctx, out, list, da);
553}
554
555
557
559
560int fr_pair_delete(fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull);
561
562/* functions for FR_TYPE_STRUCTURAL */
564
566
568
570
572
573/** Initialises a special dcursor with callbacks that will maintain the attr sublists correctly
574 *
575 * @note This is the only way to use a dcursor in non-const mode with fr_pair_list_t.
576 *
577 * @param[out] _cursor to initialise.
578 * @param[in] _list to iterate over.
579 * @param[in] _iter Iterator to use when filtering pairs.
580 * @param[in] _uctx To pass to iterator.
581 * @return
582 * - NULL if src does not point to any items.
583 * - The first pair in the list.
584 */
585#define fr_pair_dcursor_iter_init(_cursor, _list, _iter, _uctx) \
586 _fr_pair_dcursor_iter_init(_cursor, \
587 _list, \
588 _iter, \
589 _uctx, \
590 IS_CONST(fr_pair_list_t *, _list))
592 fr_dcursor_iter_t iter, void const *uctx,
593 bool is_const) CC_HINT(nonnull);
594
595/** Initialises a special dcursor with callbacks that will maintain the attr sublists correctly
596 *
597 * @note This is the only way to use a dcursor in non-const mode with fr_pair_list_t.
598 *
599 * @param[out] _cursor to initialise.
600 * @param[in] _list to iterate over.
601 * @return
602 * - NULL if src does not point to any items.
603 * - The first pair in the list.
604 */
605#define fr_pair_dcursor_init(_cursor, _list) \
606 _fr_pair_dcursor_init(_cursor, \
607 _list, \
608 IS_CONST(fr_pair_list_t *, _list))
610 bool is_const) CC_HINT(nonnull);
611
612/** Initializes a child dcursor from a parent cursor, with an iteration function.
613 *
614 * @note This is the only way to use a dcursor in non-const mode with fr_pair_list_t.
615 *
616 * @param[out] cursor to initialise.
617 * @param[in] list to iterate over.
618 * @param[in] parent parent cursor to take the iterator from
619 * @return
620 * - NULL if src does not point to any items.
621 * - The first pair in the list.
622 */
624{
625 fr_pair_t *vp = fr_pair_dcursor_init(cursor, list);
626
628 return vp;
629}
630
631/** Initialise a cursor that will return only attributes matching the specified #fr_dict_attr_t
632 *
633 * @param[in] _cursor to initialise.
634 * @param[in] _list to iterate over.
635 * @param[in] _da to search for.
636 * @return
637 * - The first matching pair.
638 * - NULL if no pairs match.
639 */
640#define fr_pair_dcursor_by_da_init(_cursor, _list, _da) \
641 _fr_pair_dcursor_by_da_init(_cursor, \
642 _list, \
643 _da, \
644 IS_CONST(fr_pair_list_t *, _list))
646 fr_pair_list_t const *list, fr_dict_attr_t const *da,
647 bool is_const) CC_HINT(nonnull);
648
649/** Initialise a cursor that will return only attributes descended from the specified #fr_dict_attr_t
650 *
651 * @param[in] _cursor to initialise.
652 * @param[in] _list to iterate over.
653 * @param[in] _da who's decentness to search for.
654 * @return
655 * - The first matching pair.
656 * - NULL if no pairs match.
657 */
658#define fr_pair_dcursor_by_ancestor_init(_cursor, _list, _da) \
659 _fr_pair_dcursor_by_ancestor_init(_cursor, \
660 _list, \
661 _da, \
662 IS_CONST(fr_pair_list_t *, _list))
664 fr_pair_list_t const *list, fr_dict_attr_t const *da,
665 bool is_const) CC_HINT(nonnull);
666
668
670
671/** Compare two attributes using and operator.
672 *
673 * @return
674 * - 1 if equal.
675 * - 0 if not equal.
676 * - -1 on failure.
677 */
678#define fr_pair_cmp_op(_op, _a, _b) fr_value_box_cmp_op(_op, &_a->data, &_b->data)
679
680fr_cmp_ret_t fr_pair_cmp_by_da(void const *a, void const *b);
681
682/*
683 * This lets us pass in a #fr_pair_t as a local structure. At some point, we may add special flags to
684 * indicate that this is pair an "on stack" variable.
685 */
686#define FR_PAIR_T_FROM_DA(_da) &(fr_pair_t) { .da = _da }
687
688#ifdef WITH_VERIFY_PTR
689fr_cmp_ret_t fr_pair_cmp_by_da_mutable(void const *a, void const *b);
690#else
691#define fr_pair_cmp_by_da_mutable fr_pair_cmp_by_da
692#endif
693
694fr_cmp_ret_t fr_pair_cmp_by_parent_num(void const *a, void const *b);
695
696int fr_pair_cmp(fr_pair_t const *a, fr_pair_t const *b);
697
699
700/* Filtering */
701void fr_pair_validate_debug(fr_pair_t const *failed[2]) CC_HINT(nonnull);
702
703bool fr_pair_validate(fr_pair_t const *failed[2], fr_pair_list_t *filter,
704 fr_pair_list_t *list) CC_HINT(nonnull(2,3));
705
706bool fr_pair_validate_relaxed(fr_pair_t const *failed[2], fr_pair_list_t *filter,
707 fr_pair_list_t *list) CC_HINT(nonnull(2,3));
708
709bool fr_pair_immutable(fr_pair_t const *vp) CC_HINT(nonnull);
710
711static inline CC_HINT(nonnull, always_inline)
713{
714 vp->vp_immutable = true;
715}
716
717static inline CC_HINT(nonnull, always_inline)
719{
720 vp->vp_immutable = false;
721}
722
723
724/* Lists */
725int fr_pair_list_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from);
726
727void fr_pair_list_steal(TALLOC_CTX *ctx, fr_pair_list_t *list);
728
730
731int fr_pair_list_copy_by_da(TALLOC_CTX *ctx, fr_pair_list_t *to,
732 fr_pair_list_t const *from, fr_dict_attr_t const *da)
733 CC_HINT(nonnull(2,3,4));
734
735int fr_pair_list_copy_by_ancestor(TALLOC_CTX *ctx, fr_pair_list_t *to,
736 fr_pair_list_t const *from,
737 fr_dict_attr_t const *parent_da) CC_HINT(nonnull);
738
739#ifndef _PAIR_INLINE
740/** @hidecallergraph */
741void fr_pair_list_free(fr_pair_list_t *list) CC_HINT(nonnull);
742
744
745
746/** @hidecallergraph */
747bool fr_pair_list_empty(fr_pair_list_t const *list) CC_HINT(nonnull);
748
749size_t fr_pair_list_num_elements(fr_pair_list_t const *list) CC_HINT(nonnull);
750
751int fr_pair_list_sort(fr_pair_list_t *list, fr_cmp_t cmp) CC_HINT(nonnull);
752
754
756
757/** @hidecallergraph */
759
760/** @hidecallergraph */
761fr_pair_t *fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item) CC_HINT(nonnull(1));
762
763fr_pair_t *fr_pair_list_prev(fr_pair_list_t const *list, fr_pair_t const *item) CC_HINT(nonnull(1));
764
766#endif
767
768/** @name Pair to pair copying
769 *
770 * @{
771 */
773
774int fr_pair_value_copy(fr_pair_t *dst, fr_pair_t *src) CC_HINT(nonnull);
775/** @} */
776
777/** @name Assign and manipulate binary-unsafe C strings
778 *
779 * @{
780 */
782 char const *value, size_t len, fr_sbuff_unescape_rules_t const *erules,
783 bool tainted) CC_HINT(nonnull(1,2));
784
785int fr_pair_value_strdup(fr_pair_t *vp, char const *src, bool tainted) CC_HINT(nonnull);
786
787int fr_pair_value_strdup_shallow(fr_pair_t *vp, char const *src, bool tainted) CC_HINT(nonnull);
788
790
792 char const *fmt, ...) CC_HINT(nonnull) CC_HINT(format (printf, 2, 3));
793/** @} */
794
795/** @name Assign and manipulate binary-safe strings
796 *
797 * @{
798 */
799int fr_pair_value_bstr_alloc(fr_pair_t *vp, char **out, size_t size, bool tainted) CC_HINT(nonnull(1));
800
801int fr_pair_value_bstr_realloc(fr_pair_t *vp, char **out, size_t size) CC_HINT(nonnull(1));
802
803int fr_pair_value_bstrndup(fr_pair_t *vp, char const *src, size_t len, bool tainted) CC_HINT(nonnull(1));
804
805int fr_pair_value_bstrdup_buffer(fr_pair_t *vp, char const *src, bool tainted) CC_HINT(nonnull);
806
807int fr_pair_value_bstrndup_shallow(fr_pair_t *vp, char const *src, size_t len, bool tainted) CC_HINT(nonnull(1));
808
809int fr_pair_value_bstrdup_buffer_shallow(fr_pair_t *vp, char const *src, bool tainted) CC_HINT(nonnull);
810
811 /** @} */
812
813/** @name Assign and manipulate octets strings
814 *
815 * @{
816 */
817int fr_pair_value_mem_alloc(fr_pair_t *vp, uint8_t **out, size_t size, bool tainted) CC_HINT(nonnull(1));
818
819int fr_pair_value_mem_realloc(fr_pair_t *vp, uint8_t **out, size_t size) CC_HINT(nonnull(1));
820
821int fr_pair_value_memdup(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted) CC_HINT(nonnull(1));
822
823int fr_pair_value_memdup_buffer(fr_pair_t *vp, uint8_t const *src, bool tainted) CC_HINT(nonnull);
824
825int fr_pair_value_memdup_shallow(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted) CC_HINT(nonnull(1));
826
827int fr_pair_value_memdup_buffer_shallow(fr_pair_t *vp, uint8_t const *src, bool tainted) CC_HINT(nonnull);
828
829 /** @} */
830
831/** @name Enum functions
832 *
833 * @{
834 */
835char const *fr_pair_value_enum(fr_pair_t const *vp, char buff[static 20]) CC_HINT(nonnull);
836
838/** @} */
839
840/** @name Printing functions
841 *
842 * @{
843 */
845 fr_pair_t const *vp, fr_token_t quote) CC_HINT(nonnull);
846
847static inline fr_slen_t CC_HINT(nonnull(2,3))
848 fr_pair_aprint_value_quoted(TALLOC_CTX *ctx, char **out,
849 fr_pair_t const *vp, fr_token_t quote)
851
853
855 fr_pair_t const *vp) CC_HINT(nonnull(1,3));
856
858 fr_pair_t const *vp) CC_HINT(nonnull(1,3));
859
861
862static inline fr_slen_t CC_HINT(nonnull(2,4))
863 fr_pair_aprint(TALLOC_CTX *ctx, char **out, fr_dict_attr_t const *parent, fr_pair_t const *vp)
865
866static inline fr_slen_t CC_HINT(nonnull(2,4))
867 fr_pair_aprint_secure(TALLOC_CTX *ctx, char **out, fr_dict_attr_t const *parent, fr_pair_t const *vp)
869
870#define fr_pair_list_log(_log, _lvl, _list) _fr_pair_list_log(_log, _lvl, NULL, _list, __FILE__, __LINE__)
871void _fr_pair_list_log(fr_log_t const *log, int lvl, fr_pair_t const *parent,
872 fr_pair_list_t const *list, char const *file, int line) CC_HINT(nonnull(1,4));
873
874void fr_pair_list_debug(FILE *fp, fr_pair_list_t const *list) CC_HINT(nonnull);
875void _fr_pair_list_debug(FILE *fp, int lvl, fr_pair_t const *parent, fr_pair_list_t const *list)
876 CC_HINT(nonnull(1, 4));
877void fr_pair_debug(FILE *fp, fr_pair_t const *pair) CC_HINT(nonnull);
878
879/** @} */
880
882
883void fr_pair_list_afrom_box(TALLOC_CTX *ctx, fr_pair_list_t *out,
884 fr_dict_t const *dict, fr_value_box_t *box) CC_HINT(nonnull);
885
886/* Tokenization */
889
890typedef struct {
891 TALLOC_CTX *ctx; //!< to allocate VPs in
892 fr_dict_attr_t const *parent; //!< current attribute to allocate VPs in
893 fr_pair_list_t *list; //!< of VPs to add
895
897void fr_pair_ctx_reset(fr_pair_ctx_t *pair_ctx, fr_dict_t const *dict) CC_HINT(nonnull);
898
899void fr_fprintf_pair(FILE *fp, char const *msg, fr_pair_t const *vp);
900void fr_fprintf_pair_list(FILE *fp, fr_pair_list_t const *list);
901
902#undef _CONST
903#ifdef __cplusplus
904}
905#endif
log_entry msg
Definition acutest.h:941
static int const char * fmt
Definition acutest.h:632
void int line
Definition acutest.h:804
#define DIAG_ON(_x)
Definition build.h:535
#define RCSIDH(h, id)
Definition build.h:561
#define DIAG_OFF(_x)
Definition build.h:534
void *(* fr_dcursor_iter_t)(fr_dcursor_t *cursor, void *to_eval, void *uctx)
Callback for implementing custom iterators.
Definition dcursor.h:49
static void fr_dcursor_copy_iter(fr_dcursor_t *out, fr_dcursor_t const *in)
Copy a read-only iterator from a parent to a child cursor.
Definition dcursor.h:205
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
Definition debug.h:177
Test enumeration values.
Definition dict_test.h:92
static void * item(fr_lst_t const *lst, fr_lst_index_t idx)
Definition lst.c:121
long int ssize_t
unsigned char uint8_t
ssize_t fr_slen_t
fr_cmp_ret_t(* fr_cmp_t)(void const *a, void const *b)
Definition misc.h:57
fr_cmp_ret_t
Result of an ordering comparison.
Definition misc.h:50
#define SBUFF_OUT_TALLOC_FUNC_NO_LEN_DEF(_func,...)
Set of parsing rules for *unescape_until functions.
static char buff[sizeof("18446744073709551615")+3]
Definition size_tests.c:37
Definition log.h:93
bool _CONST is_child
is a child of a VP
Definition pair.h:55
FR_TLIST_HEAD(fr_pair_order_list) order
Maintains the relative order of pairs in a list.
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
FR_TLIST_ENTRY(fr_pair_order_list) _CONST order_entry
Entry to maintain relative order within a list.
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
Definition pair.h:69
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
Definition table.h:804
An element in a lexicographically sorted array of name to num mappings.
Definition table.h:49
#define FR_TLIST_TYPES(_name)
Define type specific wrapper structs for tlists.
Definition tlist.h:786
enum fr_token fr_token_t
static fr_slen_t head
Definition xlat.h:410
bool fr_pair_matches_da(void const *item, void const *uctx)
Evaluation function for matching if vp matches a given da.
Definition pair.c:3444
char const * fr_pair_value_enum(fr_pair_t const *vp, char buff[static 20])
fr_pair_t * fr_pair_list_parent(fr_pair_list_t const *list)
Return a pointer to the parent pair which contains this list.
Definition pair.c:928
int fr_pair_value_bstr_alloc(fr_pair_t *vp, char **out, size_t size, bool tainted))
Pre-allocate a memory buffer for a "string" type value pair.
Definition pair.c:2694
int fr_pair_value_memdup_buffer(fr_pair_t *vp, uint8_t const *src, bool tainted)
Copy data from a talloced buffer into an "octets" data type.
Definition pair.c:2927
TALLOC_CTX * ctx
to allocate VPs in
Definition pair.h:891
int fr_pair_value_mem_alloc(fr_pair_t *vp, uint8_t **out, size_t size, bool tainted))
Pre-allocate a memory buffer for a "octets" type value pair.
Definition pair.c:2846
fr_pair_t * fr_pair_afrom_da_depth_nested(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_attr_t const *da, unsigned int start)
Create a pair (and all intermediate parents), and append it to the list.
Definition pair.c:419
struct pair_list_s fr_pair_list_t
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da))
Find the first pair with a matching da.
Definition pair.c:707
unsigned int fr_pair_count_by_da(fr_pair_list_t const *list, fr_dict_attr_t const *da)
Return the number of instances of a given da in the specified list.
Definition pair.c:684
int fr_pair_value_from_str(fr_pair_t *vp, char const *value, size_t len, fr_sbuff_unescape_rules_t const *erules, bool tainted))
static fr_pair_t * fr_pair_dcursor_child_iter_init(fr_dcursor_t *cursor, fr_pair_list_t const *list, fr_dcursor_t const *parent)
Initializes a child dcursor from a parent cursor, with an iteration function.
Definition pair.h:623
int fr_pair_value_enum_box(fr_value_box_t const **out, fr_pair_t *vp)
Get value box of a VP, optionally prefer enum value.
Definition pair.c:3027
int fr_pair_value_aprintf(fr_pair_t *vp, char const *fmt,...)
Print data into an "string" data type.
Definition pair.c:2662
int fr_pair_delete_by_da_nested(fr_pair_list_t *list, fr_dict_attr_t const *da)
Delete matching pairs from the specified list, and prune any empty branches.
Definition pair.c:1665
int fr_pair_insert_after(fr_pair_list_t *list, fr_pair_t *pos, fr_pair_t *to_add))
Add a VP after another VP.
Definition pair.c:1323
void _fr_pair_list_log(fr_log_t const *log, int lvl, fr_pair_t const *parent, fr_pair_list_t const *list, char const *file, int line))
Print a list of attributes and enumv.
Definition pair_print.c:381
void fr_fprintf_pair_list(FILE *fp, fr_pair_list_t const *list)
Definition pair_print.c:481
int fr_pair_value_memdup(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted))
Copy data into an "octets" data type.
Definition pair.c:2897
bool fr_pair_validate_relaxed(fr_pair_t const *failed[2], fr_pair_list_t *filter, fr_pair_list_t *list))
Uses fr_pair_cmp to verify all fr_pair_ts in list match the filter defined by check.
Definition pair.c:2181
static bool vp_da_data_type_check(fr_pair_t *vp)
Check a pair's data type matches the DA data type.
Definition pair.h:266
ssize_t fr_pair_print(fr_sbuff_t *out, fr_dict_attr_t const *parent, fr_pair_t const *vp))
Print one attribute and value to a string.
Definition pair_print.c:232
int fr_pair_list_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from)
Duplicate a list of pairs.
Definition pair.c:2303
int fr_pair_value_mem_realloc(fr_pair_t *vp, uint8_t **out, size_t size))
Change the length of a buffer for a "octets" type value pair.
Definition pair.c:2871
int fr_pair_insert_before(fr_pair_list_t *list, fr_pair_t *pos, fr_pair_t *to_add))
Add a VP before another VP.
Definition pair.c:1356
void fr_pair_debug(FILE *fp, fr_pair_t const *pair)
Dumps a pair to the default logging destination - Useful for calling from debuggers.
Definition pair_print.c:449
static fr_slen_t fr_pair_aprint(TALLOC_CTX *ctx, char **out, fr_dict_attr_t const *parent, fr_pair_t const *vp) 1(fr_pair_print
bool fr_pair_list_empty(fr_pair_list_t const *list)
Is a valuepair list empty.
fr_pair_t * fr_pair_root_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
A special allocation function which disables child autofree.
Definition pair.c:242
int fr_pair_append_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, fr_dict_attr_t const *da))
Alloc a new fr_pair_t (and append)
Definition pair.c:1416
fr_pair_t * fr_pair_find_by_da_nested(fr_pair_list_t const *list, fr_dict_attr_t const *da)
Find a pair with a matching fr_dict_attr_t, by walking the nested fr_dict_attr_t tree.
Definition pair.c:782
fr_cmp_ret_t fr_pair_list_cmp(fr_pair_list_t const *a, fr_pair_list_t const *b)
Determine equality of two lists.
Definition pair.c:2027
void fr_pair_validate_debug(fr_pair_t const *failed[2])
Write an error to the library errorbuff detailing the mismatch.
Definition pair.c:2069
int fr_pair_value_strdup(fr_pair_t *vp, char const *src, bool tainted)
Copy data into an "string" data type.
Definition pair.c:2598
int fr_pair_steal_append(TALLOC_CTX *nctx, fr_pair_list_t *list, fr_pair_t *vp)
Change a vp's talloc ctx and insert it into a new list.
Definition pair.c:562
#define fr_pair_cmp_by_da_mutable
Definition pair.h:691
int fr_pair_value_bstrdup_buffer_shallow(fr_pair_t *vp, char const *src, bool tainted)
Assign a string to a "string" type value pair.
Definition pair.c:2818
void fr_pair_init_null(fr_pair_t *vp)
Initialise fields in an fr_pair_t without assigning a da.
Definition pair.c:150
int fr_pair_delete_by_da(fr_pair_list_t *head, fr_dict_attr_t const *da)
Delete matching pairs from the specified list.
Definition pair.c:1641
fr_pair_list_t * fr_pair_parent_list(fr_pair_t const *vp)
Return a pointer to the parent pair list.
Definition pair.c:906
fr_pair_t * fr_pair_find_by_child_num_idx(fr_pair_list_t const *list, fr_dict_attr_t const *parent, unsigned int attr, unsigned int idx)
Find the pair with the matching child attribute at a given index.
Definition pair.c:872
int fr_pair_cmp(fr_pair_t const *a, fr_pair_t const *b)
Compare two pairs, using the operator from "a".
Definition pair.c:1949
fr_pair_list_t * fr_pair_list_alloc(TALLOC_CTX *ctx)
Allocate a new pair list on the heap.
Definition pair.c:120
fr_slen_t fr_pair_ctx_afrom_substr(fr_pair_ctx_t *pair_ctx, fr_sbuff_t *in)
Parse one pair, or one context change, from a string.
fr_pair_t * fr_pair_parent(fr_pair_t const *vp)
Return a pointer to the parent pair.
Definition pair.c:914
fr_cmp_ret_t fr_pair_cmp_by_da(void const *a, void const *b)
Order attributes by their da.
Definition pair.c:1796
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
fr_pair_t * _fr_pair_dcursor_by_ancestor_init(fr_dcursor_t *cursor, fr_pair_list_t const *list, fr_dict_attr_t const *da, bool is_const)
Initialise a cursor that will return only attributes descended from the specified fr_dict_attr_t.
Definition pair.c:1119
void fr_pair_replace(fr_pair_list_t *list, fr_pair_t *to_replace, fr_pair_t *vp)
Replace a given VP.
Definition pair.c:1389
fr_pair_t * fr_pair_find_by_da_idx(fr_pair_list_t const *list, fr_dict_attr_t const *da, unsigned int idx)
Find a pair with a matching da at a given index.
Definition pair.c:754
fr_pair_t * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute and assign a fr_dict_attr_t.
Definition pair.c:284
int fr_pair_prepend(fr_pair_list_t *list, fr_pair_t *vp)
Add a VP to the start of the list.
Definition pair.c:1266
int fr_pair_value_memdup_shallow(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted))
Assign a buffer to a "octets" type value pair.
Definition pair.c:2952
int fr_pair_value_bstrdup_buffer(fr_pair_t *vp, char const *src, bool tainted)
Copy a nul terminated talloced buffer a "string" type value pair.
Definition pair.c:2773
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
int fr_pair_list_copy_by_ancestor(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from, fr_dict_attr_t const *parent_da)
Duplicate pairs in a list where the da is a descendant of parent_da.
Definition pair.c:2435
static bool fr_pair_nonnull_assert(fr_pair_t const *vp)
If WITH_VERIFY_PTR is defined, we perform runtime checks to ensure the fr_pair_t are sane.
Definition pair.h:193
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
fr_pair_list_t * fr_pair_children(fr_pair_t *head)
Get the child list of a group.
Definition pair.c:896
int fr_pair_value_bstrndup(fr_pair_t *vp, char const *src, size_t len, bool tainted))
Copy data into a "string" type value pair.
Definition pair.c:2747
int fr_pair_list_copy_by_da(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from, fr_dict_attr_t const *da))
Duplicate pairs in a list matching the specified da.
Definition pair.c:2391
static int fr_pair_find_or_append_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, fr_dict_attr_t const *da)
Definition pair.h:541
void fr_pair_list_free(fr_pair_list_t *list)
Free memory used by a valuepair list.
static void fr_pair_clear_immutable(fr_pair_t *vp)
Definition pair.h:718
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.
void fr_pair_list_debug(FILE *fp, fr_pair_list_t const *list)
Dumps a list to the default logging destination - Useful for calling from debuggers.
Definition pair_print.c:440
fr_pair_t * fr_pair_find_last_by_da(fr_pair_list_t const *list, fr_dict_attr_t const *da)
Find the last pair with a matching da.
Definition pair.c:730
void fr_pair_ctx_reset(fr_pair_ctx_t *pair_ctx, fr_dict_t const *dict)
Reset a pair_ctx to the dictionary root.
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *vp)
Add a VP to the end of the list.
Definition pair.c:1297
#define _CONST
Definition pair.h:43
void fr_fprintf_pair(FILE *fp, char const *msg, fr_pair_t const *vp)
Definition pair_print.c:489
void _fr_pair_list_debug(FILE *fp, int lvl, fr_pair_t const *parent, fr_pair_list_t const *list))
Print a list of attributes and enumv.
Definition pair_print.c:427
fr_pair_t * fr_pair_alloc_null(TALLOC_CTX *ctx)
Dynamically allocate a new attribute with no fr_dict_attr_t assigned.
Definition pair.c:170
int fr_pair_value_bstrndup_shallow(fr_pair_t *vp, char const *src, size_t len, bool tainted))
Assign a string to a "string" type value pair.
Definition pair.c:2798
fr_cmp_ret_t fr_pair_cmp_by_parent_num(void const *a, void const *b)
Order attributes by their parent(s), attribute number, and tag.
Definition pair.c:1901
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.
bool fr_pair_immutable(fr_pair_t const *vp)
Definition pair.c:2256
void fr_pair_list_tainted(fr_pair_list_t *vps)
Mark up a list of VPs as tainted.
Definition pair.c:3417
void fr_pair_value_clear(fr_pair_t *vp)
Free/zero out value (or children) of a given VP.
Definition pair.c:2485
int 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.
static void fr_pair_set_immutable(fr_pair_t *vp)
Definition pair.h:712
fr_pair_list_t * list
of VPs to add
Definition pair.h:893
int fr_pair_delete(fr_pair_list_t *list, fr_pair_t *vp)
Remove fr_pair_t from a list and free.
Definition pair.c:1778
static fr_slen_t vp
Definition pair.h:850
int fr_pair_delete_by_child_num(fr_pair_list_t *list, fr_dict_attr_t const *parent, unsigned int attr)
Delete matching pairs from the specified list.
Definition pair.c:1760
int fr_pair_value_copy(fr_pair_t *dst, fr_pair_t *src)
Copy the value from one pair to another.
Definition pair.c:2515
fr_pair_t * _fr_pair_dcursor_init(fr_dcursor_t *cursor, fr_pair_list_t const *list, bool is_const)
Initialises a special dcursor with callbacks that will maintain the attr sublists correctly.
Definition pair.c:1082
static bool fr_pair_list_nonnull_assert(fr_pair_list_t const *pair_list)
Definition pair.h:198
static fr_slen_t quote ssize_t fr_pair_print_name(fr_sbuff_t *out, fr_dict_attr_t const *parent, fr_pair_t const **vp_p)
Print an attribute name.
Definition pair_print.c:136
ssize_t fr_pair_print_value_quoted(fr_sbuff_t *out, fr_pair_t const *vp, fr_token_t quote)
Print the value of an attribute to a string.
Definition pair_print.c:59
fr_pair_t * fr_pair_copy(TALLOC_CTX *ctx, fr_pair_t const *vp))
Copy a single valuepair.
Definition pair.c:500
int fr_pair_steal(TALLOC_CTX *ctx, fr_pair_t *vp)
Steal one VP.
Definition pair.c:534
bool fr_pair_validate(fr_pair_t const *failed[2], fr_pair_list_t *filter, fr_pair_list_t *list))
Uses fr_pair_cmp to verify all fr_pair_ts in list match the filter defined by check.
Definition pair.c:2104
static fr_slen_t fr_pair_aprint_value_quoted(TALLOC_CTX *ctx, char **out, fr_pair_t const *vp, fr_token_t quote) 1(fr_pair_print_value_quoted
fr_table_num_sorted_t const fr_pair_comparison_op_table[]
Operators that may appear between an attribute name and a value.
fr_value_box_t * fr_pair_dcursor_nested_init(fr_dcursor_t *cursor, fr_dcursor_t *parent)
Initialises a special dcursor over another cursor which returns fr_pair_t, but we return fr_value_box...
Definition pair.c:1250
int fr_pair_append_by_da_parent(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, fr_dict_attr_t const *da))
Alloc a new fr_pair_t, adding the parent attributes if required.
Definition pair.c:1473
fr_pair_t * _fr_pair_dcursor_by_da_init(fr_dcursor_t *cursor, fr_pair_list_t const *list, fr_dict_attr_t const *da, bool is_const)
Initialise a cursor that will return only attributes matching the specified fr_dict_attr_t.
Definition pair.c:1100
int fr_pair_value_strtrim(fr_pair_t *vp)
Trim the length of the string buffer to match the length of the C string.
Definition pair.c:2641
fr_pair_t * fr_pair_afrom_da_nested(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_attr_t const *da)
Create a pair (and all intermediate parents), and append it to the list.
Definition pair.c:477
#define fr_pair_dcursor_init(_cursor, _list)
Initialises a special dcursor with callbacks that will maintain the attr sublists correctly.
Definition pair.h:605
fr_dict_attr_t const * parent
current attribute to allocate VPs in
Definition pair.h:892
int fr_pair_update_by_da_parent(fr_pair_t *parent, fr_pair_t **out, fr_dict_attr_t const *da))
Return the first fr_pair_t matching the fr_dict_attr_t or alloc a new fr_pair_t and its subtree (and ...
Definition pair.c:1547
void fr_pair_list_init(fr_pair_list_t *head)
Initialise a pair list header.
Definition pair.c:47
int fr_pair_reinit_from_da(fr_pair_list_t *list, fr_pair_t *vp, fr_dict_attr_t const *da))
Re-initialise an attribute with a different da.
Definition pair.c:321
int fr_pair_value_bstr_realloc(fr_pair_t *vp, char **out, size_t size))
Change the length of a buffer for a "string" type value pair.
Definition pair.c:2719
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
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
fr_value_box_t * fr_pair_dcursor_value_init(fr_dcursor_t *cursor)
Initialises a special dcursor over a fr_pair_list_t, but which returns fr_value_box_t.
Definition pair.c:1203
void fr_pair_list_afrom_box(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dict, fr_value_box_t *box)
Parse a list of VPs from a value box.
Definition pair.c:3529
fr_pair_t * fr_pair_list_iter_leaf(fr_pair_list_t *list, fr_pair_t *vp)
Iterates over the leaves of a list.
Definition pair.c:997
void fr_pair_list_steal(TALLOC_CTX *ctx, fr_pair_list_t *list)
Steal a list of pairs to a new context.
Definition pair.c:2280
size_t fr_pair_list_num_elements(fr_pair_list_t const *list)
Get the length of a list of fr_pair_t.
int fr_pair_steal_prepend(TALLOC_CTX *nctx, fr_pair_list_t *list, fr_pair_t *vp)
Change a vp's talloc ctx and insert it into a new list.
Definition pair.c:585
int fr_pair_prepend_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, fr_dict_attr_t const *da))
Alloc a new fr_pair_t (and prepend)
Definition pair.c:1443
int fr_pair_raw_afrom_pair(fr_pair_t *vp, uint8_t const *data, size_t data_len)
Mark malformed attribute as raw.
Definition pair.c:609
ssize_t fr_pair_print_secure(fr_sbuff_t *out, fr_dict_attr_t const *parent, fr_pair_t const *vp))
Print one attribute and value to a string with escape rules.
Definition pair_print.c:267
int fr_pair_value_memdup_buffer_shallow(fr_pair_t *vp, uint8_t const *src, bool tainted)
Assign a talloced buffer to a "octets" type value pair.
Definition pair.c:2972
int fr_pair_value_strdup_shallow(fr_pair_t *vp, char const *src, bool tainted)
Assign a buffer containing a nul terminated string to a vp, but don't copy it.
Definition pair.c:2622
ssize_t fr_pair_list_print(fr_sbuff_t *out, fr_dict_attr_t const *parent, fr_pair_list_t const *list)
Print a pair list.
Definition pair_print.c:316
static fr_slen_t parent
Definition pair.h:864
fr_pair_t * _fr_pair_dcursor_iter_init(fr_dcursor_t *cursor, fr_pair_list_t const *list, fr_dcursor_iter_t iter, void const *uctx, bool is_const)
Initialises a special dcursor with callbacks that will maintain the attr sublists correctly.
Definition pair.c:1062
size_t fr_pair_comparison_op_table_len
int fr_pair_list_copy_to_box(fr_value_box_t *dst, fr_pair_list_t *from)
Copy the contents of a pair list to a set of value-boxes.
Definition pair.c:2338
fr_pair_t * fr_pair_afrom_child_num(TALLOC_CTX *ctx, fr_dict_attr_t const *parent, unsigned int attr)
Create a new valuepair.
Definition pair.c:381
static fr_slen_t static vp fr_slen_t fr_pair_aprint_secure(TALLOC_CTX *ctx, char **out, fr_dict_attr_t const *parent, fr_pair_t const *vp) 1(fr_pair_print_secure
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
Definition strerror.h:64
fr_table_num_ordered_t const fr_type_table[]
Map data types to names representing those types.
Definition types.c:31
static fr_sbuff_err_t char size_t fr_sbuff_t * in
Definition value.h:1061
static fr_slen_t data
Definition value.h:1366
static fr_sbuff_err_t char ** out
Definition value.h:1061
static fr_sbuff_err_t char size_t * len
Definition value.h:1061
int nonnull(2, 5))