The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
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: 600a70cf60e6cf0260bbdae2ddc72e58fc334309 $")
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 type 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, safe_for)];
96
97 fr_pair_list_t children; //!< Nested attributes of this pair.
98 };
99 };
100
101 /*
102 * Legacy stuff that needs to die.
103 */
104 struct {
105 fr_token_t op; //!< Operator to use when moving or inserting
106 };
107};
108
109#define vp_strvalue data.vb_strvalue
110#define vp_octets data.vb_octets
111#define vp_ptr data.datum.ptr //!< Either octets or strvalue
112#define vp_length data.vb_length
113
114#define vp_ipv4addr data.vb_ip.addr.v4.s_addr
115#define vp_ipv6addr data.vb_ip.addr.v6.s6_addr
116#define vp_ip data.vb_ip
117#define vp_ifid data.vb_ifid
118#define vp_ether data.vb_ether
119
120#define vp_bool data.datum.boolean
121#define vp_uint8 data.vb_uint8
122#define vp_uint16 data.vb_uint16
123#define vp_uint32 data.vb_uint32
124#define vp_uint64 data.vb_uint64
125
126#define vp_int8 data.vb_int8
127#define vp_int16 data.vb_int16
128#define vp_int32 data.vb_int32
129#define vp_int64 data.vb_int64
130
131#define vp_float32 data.vb_float32
132#define vp_float64 data.vb_float64
133
134#define vp_attr data.vb_attr
135
136#define vp_date data.vb_date
137#define vp_time_delta data.vb_time_delta
138
139#define vp_group children
140
141#define vp_size data.datum.size
142#define vp_filter data.datum.filter
143
144#define vp_type data.type
145#define vp_tainted data.tainted
146#define vp_immutable data.immutable
147#define vp_edit data.edit
148#define vp_raw da->flags.is_raw
149
150#define ATTRIBUTE_EQ(_x, _y) ((_x && _y) && (_x->da == _y->da))
151
152/** If WITH_VERIFY_PTR is defined, we perform runtime checks to ensure the fr_pair_t are sane
153 *
154 */
155#ifdef WITH_VERIFY_PTR
156void fr_pair_verify(char const *file, int line, fr_pair_list_t const *list, fr_pair_t const *vp) CC_HINT(nonnull(4));
157
158void fr_pair_list_verify(char const *file, int line,
159 TALLOC_CTX const *expected, fr_pair_list_t const *list) CC_HINT(nonnull(4));
160
161# define PAIR_VERIFY(_x) fr_pair_verify(__FILE__, __LINE__, NULL, _x)
162# define PAIR_VERIFY_WITH_LIST(_l, _x) fr_pair_verify(__FILE__, __LINE__, _l, _x)
163# define PAIR_LIST_VERIFY(_x) fr_pair_list_verify(__FILE__, __LINE__, NULL, _x)
164#else
165DIAG_OFF(nonnull-compare)
166/** Wrapper function to defeat nonnull checks
167 *
168 * We may sprinkle PAIR_VERIFY and PAIR_LIST_VERIFY in functions which
169 * have their pair argument marked up as nonnull.
170 *
171 * This would usually generate errors when WITH_VERIFY_PTR is not
172 * defined, as the assert macros check for an arguments NULLness.
173 *
174 * This function wraps the assert but has nonnull-compare disabled
175 * meaning a warning won't be emitted.
176 */
177static inline bool fr_pair_nonnull_assert(fr_pair_t const *vp)
178{
179 return fr_cond_assert(vp);
180}
181
183{
185}
186DIAG_ON(nonnull-compare)
187
188/*
189 * Even if were building without WITH_VERIFY_PTR
190 * the pointer must not be NULL when these various macros are used
191 * so we can add some sneaky soft asserts.
192 */
193# define PAIR_VERIFY(_x) fr_pair_nonnull_assert(_x)
194# define PAIR_VERIFY_WITH_LIST(_l, _x) fr_pair_list_nonnull_assert(_l); \
195 fr_pair_nonnull_assert(_x)
196# define PAIR_LIST_VERIFY(_x) fr_pair_list_nonnull_assert(_x)
197#endif
198
199
200#ifdef TEST_CHECK
201/** Macro for use in acutest tests
202 */
203#define TEST_CHECK_PAIR(_got, _exp) \
204do { \
205 fr_pair_t const *_our_got = (_got); \
206 fr_pair_t const *_our_exp = (_exp); \
207 TEST_CHECK_(_our_exp == _our_got, "%s", #_got); \
208 if (_our_exp) { \
209 TEST_MSG("Expected pair : %s - %p (%s)", (_our_exp)->da->name, _our_exp, talloc_get_name(_our_exp)); \
210 } else { \
211 TEST_MSG("Expected pair : NULL"); \
212 } \
213 if (_our_got) { \
214 TEST_MSG("Got pair : %s - %p (%s)", (_our_got)->da->name, _our_got, talloc_get_name(_our_got)); \
215 } else { \
216 TEST_MSG("Got Pair : NULL"); \
217 } \
218} while(0)
219
220#define TEST_CHECK_PAIR_NEQ(_got, _neq) \
221do { \
222 fr_pair_t const *_our_got = (_got); \
223 fr_pair_t const *_our_neq = (_neq); \
224 TEST_CHECK_(_our_got != _our_neq, "%s", #_got); \
225 if (_our_neq) { \
226 TEST_MSG("Pair must not equal : %s - %p (%s)", (_our_neq)->da->name, _our_neq, talloc_get_name(_our_neq)); \
227 } else { \
228 TEST_MSG("Pair must not equal : NULL"); \
229 } \
230} while(0)
231#endif
232
233/*
234 * Helper macros for adding pairs to lists and assigning a value to them
235 */
236
237/** Check a pair's data type matches the DA data type
238 *
239 * @param[in] vp to check consistency of.
240 * @return
241 * - true for match
242 * - false for error
243 */
245{
246 if (vp->vp_type == vp->da->type) return true;
247
248 fr_strerror_printf("fr_pair_t attribute %p \"%s\" data type (%s) does not match da type (%s)",
249 vp->da, vp->da->name,
250 fr_table_str_by_value(fr_type_table, vp->vp_type, "invalid"),
251 fr_table_str_by_value(fr_type_table, vp->da->type, "invalid"));
252 return false;
253}
254
255/** Iterate over the contents of a #fr_pair_list_t
256 *
257 * The iteration variable can be safely removed from the list at each pass.
258 *
259 * @param[in] _list_head to iterate over.
260 * @param[in] _iter Name of iteration variable.
261 * Will be declared in the scope of the loop.
262 */
263#define fr_pair_list_foreach(_list_head, _iter) \
264 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))
265
266/** Iterate over the leaf nodes of a #fr_pair_list_t
267 *
268 * The iteration variable CANNOT be modified. This is a read-only operation.
269 *
270 * @param[in] _list_head to iterate over.
271 * @param[in] _iter Name of iteration variable.
272 * Will be declared in the scope of the loop.
273 */
274#define fr_pair_list_foreach_leaf(_list_head, _iter) \
275 for (fr_pair_t *_iter = fr_pair_list_iter_leaf(_list_head, NULL); _iter != NULL; _iter = fr_pair_list_iter_leaf(_list_head, _iter))
276
277/** Append a pair to a list, assigning its value.
278 *
279 * Version for simple C data types
280 *
281 * @param[in] _ctx to allocate the pair in
282 * @param[out] _vp the allocated pair
283 * @param[in] _list to append the pair to
284 * @param[in] _attr to use when creating pair
285 * @param[in] _val to assign to the pair
286 * @param[in] _tainted does the value come from a trusted source
287 */
288#define fr_pair_list_append_by_da(_ctx, _vp, _list, _attr, _val, _tainted) \
289do { \
290 _vp = NULL; \
291 if (fr_pair_append_by_da(_ctx, &_vp, _list, _attr) < 0) break; \
292 fr_value_box(&_vp->data, _val, _tainted); \
293 if (!vp_da_data_type_check(_vp)) { \
294 fr_pair_delete(_list, _vp); \
295 _vp = NULL; \
296 } \
297} while (0)
298
299/** Append a pair to a list, assigning its value.
300 *
301 * Version for char* and uint8_t*
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] _len of value
309 * @param[in] _tainted does the value come from a trusted source
310 */
311#define fr_pair_list_append_by_da_len(_ctx, _vp, _list, _attr, _val, _len, _tainted) \
312do { \
313 _vp = NULL; \
314 if (fr_pair_append_by_da(_ctx, &_vp, _list, _attr) < 0) break; \
315 fr_value_box_len(_vp, &_vp->data, _val, _len, _tainted); \
316 if (!vp_da_data_type_check(_vp)) { \
317 fr_pair_delete(_list, _vp); \
318 _vp = NULL; \
319 } \
320} while (0)
321
322#define fr_pair_list_append_by_da_parent(_ctx, _vp, _list, _attr, _val, _tainted) \
323do { \
324 _vp = NULL; \
325 if (fr_pair_append_by_da_parent(_ctx, &_vp, _list, _attr) < 0) break; \
326 fr_value_box(&_vp->data, _val, _tainted); \
327 if (!vp_da_data_type_check(_vp)) { \
328 fr_pair_delete(_list, _vp); \
329 _vp = NULL; \
330 } \
331} while (0)
332
333#define fr_pair_list_append_by_da_parent_len(_ctx, _vp, _list, _attr, _val, _len, _tainted) \
334do { \
335 _vp = NULL; \
336 if (fr_pair_append_by_da_parent(_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/** Prepend a pair to a list, assigning its value
345 *
346 * Version for simple C data types
347 *
348 * @param[in] _ctx to allocate the pair in
349 * @param[out] _vp the allocated pair
350 * @param[in] _list to prepend the pair to
351 * @param[in] _attr to use when creating pair
352 * @param[in] _val to assign to the pair
353 * @param[in] _tainted does the value come from a trusted source
354 */
355#define fr_pair_list_prepend_by_da(_ctx, _vp, _list, _attr, _val, _tainted) \
356do { \
357 _vp = NULL; \
358 if (fr_pair_prepend_by_da(_ctx, &_vp, _list, _attr) < 0) break; \
359 fr_value_box(&_vp->data, _val, _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 char* and uint8_t*
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] _len of value
376 * @param[in] _tainted does the value come from a trusted source
377 */
378#define fr_pair_list_prepend_by_da_len(_ctx, _vp, _list, _attr, _val, _len, _tainted) \
379do { \
380 _vp = NULL; \
381 if (fr_pair_prepend_by_da(_ctx, &_vp, _list, _attr) < 0) break; \
382 fr_value_box_len(_vp, &_vp->data, _val, _len, _tainted); \
383 if (!vp_da_data_type_check(_vp)) { \
384 fr_pair_delete(_list, _vp); \
385 _vp = NULL; \
386 } \
387} while (0)
388
389/** Replace a pair in a list, assigning its value
390 *
391 * Version for simple C data types.
392 * If the pair does not already exist, a new one is allocated.
393 *
394 * @param[in] _ctx to allocate the pair in
395 * @param[out] _vp the allocated pair
396 * @param[in] _list to append the pair to
397 * @param[in] _attr to use when creating pair
398 * @param[in] _val to assign to the pair
399 * @param[in] _tainted does the value come from a trusted source
400 */
401#define fr_pair_list_replace_by_da(_ctx, _vp, _list, _attr, _val, _tainted) \
402do { \
403 fr_pair_update_by_da(_ctx, _vp, _list, _attr, 0); \
404 if (!vp) break; \
405 fr_value_box(&_vp->data, _val, _tainted); \
406 if (!vp_da_data_type_check(_vp)) { \
407 fr_pair_delete(_list, _vp); \
408 _vp = NULL; \
409 } \
410} while (0)
411
412/** Replace a pair in a list, assigning its value
413 *
414 * Version for char* and uint8_t*
415 * If the pair does not already exist, a new one is allocated.
416 *
417 * @param[in] _ctx to allocate the pair in
418 * @param[out] _vp the allocated pair
419 * @param[in] _list to append the pair to
420 * @param[in] _attr to use when creating pair
421 * @param[in] _val to assign to the pair
422 * @param[in] _len of value
423 * @param[in] _tainted does the value come from a trusted source
424 */
425#define fr_pair_list_replace_by_da_len(_ctx, _vp, _list, _attr, _val, _len, _tainted) \
426do { \
427 fr_pair_t *oldvp = fr_pair_find_by_da(_list, NULL, _attr); \
428 fr_pair_list_append_by_da_len(_ctx, _vp_, _list, _attr, _val, _len, _tainted) \
429 if (!vp_da_data_type_check(_vp)) { \
430 fr_pair_delete(_list, _vp); \
431 _vp = NULL; \
432 } \
433 if (!_vp) break; \
434 if (oldvp) fr_pair_delete(_list, oldvp); \
435} while (0)
436
437/* Initialisation */
438/** @hidecallergraph */
440
441void fr_pair_init_null(fr_pair_t *vp) CC_HINT(nonnull);
442
443/* Allocation and management */
444fr_pair_t *fr_pair_alloc_null(TALLOC_CTX *ctx) CC_HINT(warn_unused_result);
445
446fr_pair_list_t *fr_pair_list_alloc(TALLOC_CTX *ctx) CC_HINT(warn_unused_result);
447
448fr_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));
449
450/** @hidecallergraph */
451fr_pair_t *fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da) CC_HINT(warn_unused_result) CC_HINT(nonnull(2));
452
454 CC_HINT(nonnull(2, 3));
455
456fr_pair_t *fr_pair_afrom_child_num(TALLOC_CTX *ctx, fr_dict_attr_t const *parent, unsigned int attr) CC_HINT(warn_unused_result);
457
458fr_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));
459
460fr_pair_t *fr_pair_afrom_da_depth_nested(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_attr_t const *da, int start) CC_HINT(warn_unused_result) CC_HINT(nonnull(2,3));
461
462fr_pair_t *fr_pair_copy(TALLOC_CTX *ctx, fr_pair_t const *vp) CC_HINT(nonnull(2)) CC_HINT(warn_unused_result);
463
464int fr_pair_steal(TALLOC_CTX *ctx, fr_pair_t *vp) CC_HINT(nonnull);
465
466int fr_pair_steal_append(TALLOC_CTX *nctx, fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull);
467
468int fr_pair_steal_prepend(TALLOC_CTX *nctx, fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull);
469
470/* Searching and list modification */
471int fr_pair_raw_afrom_pair(fr_pair_t *vp, uint8_t const *data, size_t data_len) CC_HINT(nonnull);
472
473bool fr_pair_matches_da(void const *item, void const *uctx) CC_HINT(nonnull);
474
475/** @hidecallergraph */
476unsigned int fr_pair_count_by_da(fr_pair_list_t const *list, fr_dict_attr_t const *da)
477 CC_HINT(nonnull);
478
479/** @hidecallergraph */
481 fr_pair_t const *prev, fr_dict_attr_t const *da) CC_HINT(nonnull(1,3));
482
484 fr_dict_attr_t const *da, unsigned int idx) CC_HINT(nonnull);
485
487 fr_dict_attr_t const *da) CC_HINT(nonnull(1,3));
488
490 fr_pair_t const *prev, fr_dict_attr_t const *da) CC_HINT(nonnull(1,3));
491
493 fr_dict_attr_t const *parent, unsigned int attr) CC_HINT(nonnull(1,3));
494
496 fr_dict_attr_t const *parent, unsigned int attr,
497 unsigned int idx) CC_HINT(nonnull);
498
499/** @hidecallergraph */
500int fr_pair_append(fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull);
501
503
504int fr_pair_insert_after(fr_pair_list_t *list, fr_pair_t *pos, fr_pair_t *to_add) CC_HINT(nonnull(1,3));
505
506int fr_pair_insert_before(fr_pair_list_t *list, fr_pair_t *pos, fr_pair_t *to_add) CC_HINT(nonnull(1,3));
507
508void fr_pair_replace(fr_pair_list_t *list, fr_pair_t *to_replace, fr_pair_t *vp) CC_HINT(nonnull);
509
511 fr_dict_attr_t const *parent, unsigned int attr) CC_HINT(nonnull);
512
513int fr_pair_append_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list,
514 fr_dict_attr_t const *da) CC_HINT(nonnull(3,4));
515
516int fr_pair_prepend_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list,
517 fr_dict_attr_t const *da) CC_HINT(nonnull(3,4));
518
519int fr_pair_append_by_da_parent(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list,
520 fr_dict_attr_t const *da) CC_HINT(nonnull(3,4));
521
523 fr_dict_attr_t const *da) CC_HINT(nonnull(1,3));
524
525static 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,
526 fr_dict_attr_t const *da)
527{
528 fr_pair_t *vp;
529
530 vp = fr_pair_find_by_da(list, NULL, da);
531 if (vp) {
532 *out = vp;
533 return 0;
534 }
535
536 return fr_pair_append_by_da(ctx, out, list, da);
537}
538
539
541
543
544int fr_pair_delete(fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull);
545
546/* functions for FR_TYPE_STRUCTURAL */
548
550
552
554
556
557/** Initialises a special dcursor with callbacks that will maintain the attr sublists correctly
558 *
559 * @note This is the only way to use a dcursor in non-const mode with fr_pair_list_t.
560 *
561 * @param[out] _cursor to initialise.
562 * @param[in] _list to iterate over.
563 * @param[in] _iter Iterator to use when filtering pairs.
564 * @param[in] _uctx To pass to iterator.
565 * @return
566 * - NULL if src does not point to any items.
567 * - The first pair in the list.
568 */
569#define fr_pair_dcursor_iter_init(_cursor, _list, _iter, _uctx) \
570 _fr_pair_dcursor_iter_init(_cursor, \
571 _list, \
572 _iter, \
573 _uctx, \
574 IS_CONST(fr_pair_list_t *, _list))
576 fr_dcursor_iter_t iter, void const *uctx,
577 bool is_const) CC_HINT(nonnull);
578
579/** Initialises a special dcursor with callbacks that will maintain the attr sublists correctly
580 *
581 * @note This is the only way to use a dcursor in non-const mode with fr_pair_list_t.
582 *
583 * @param[out] _cursor to initialise.
584 * @param[in] _list to iterate over.
585 * @return
586 * - NULL if src does not point to any items.
587 * - The first pair in the list.
588 */
589#define fr_pair_dcursor_init(_cursor, _list) \
590 _fr_pair_dcursor_init(_cursor, \
591 _list, \
592 IS_CONST(fr_pair_list_t *, _list))
594 bool is_const) CC_HINT(nonnull);
595
596/** Initializes a child dcursor from a parent cursor, with an iteration function.
597 *
598 * @note This is the only way to use a dcursor in non-const mode with fr_pair_list_t.
599 *
600 * @param[out] cursor to initialise.
601 * @param[in] list to iterate over.
602 * @param[in] parent parent cursor to take the iterator from
603 * @return
604 * - NULL if src does not point to any items.
605 * - The first pair in the list.
606 */
608{
609 fr_pair_t *vp = fr_pair_dcursor_init(cursor, list);
610
612 return vp;
613}
614
615/** Initialise a cursor that will return only attributes matching the specified #fr_dict_attr_t
616 *
617 * @param[in] _cursor to initialise.
618 * @param[in] _list to iterate over.
619 * @param[in] _da to search for.
620 * @return
621 * - The first matching pair.
622 * - NULL if no pairs match.
623 */
624#define fr_pair_dcursor_by_da_init(_cursor, _list, _da) \
625 _fr_pair_dcursor_by_da_init(_cursor, \
626 _list, \
627 _da, \
628 IS_CONST(fr_pair_list_t *, _list))
630 fr_pair_list_t const *list, fr_dict_attr_t const *da,
631 bool is_const) CC_HINT(nonnull);
632
633/** Initialise a cursor that will return only attributes descended from the specified #fr_dict_attr_t
634 *
635 * @param[in] _cursor to initialise.
636 * @param[in] _list to iterate over.
637 * @param[in] _da who's decentness to search for.
638 * @return
639 * - The first matching pair.
640 * - NULL if no pairs match.
641 */
642#define fr_pair_dcursor_by_ancestor_init(_cursor, _list, _da) \
643 _fr_pair_dcursor_by_ancestor_init(_cursor, \
644 _list, \
645 _da, \
646 IS_CONST(fr_pair_list_t *, _list))
648 fr_pair_list_t const *list, fr_dict_attr_t const *da,
649 bool is_const) CC_HINT(nonnull);
650
652
654
655/** Compare two attributes using and operator.
656 *
657 * @return
658 * - 1 if equal.
659 * - 0 if not equal.
660 * - -1 on failure.
661 */
662#define fr_pair_cmp_op(_op, _a, _b) fr_value_box_cmp_op(_op, &_a->data, &_b->data)
663
664int8_t fr_pair_cmp_by_da(void const *a, void const *b);
665
666int8_t fr_pair_cmp_by_parent_num(void const *a, void const *b);
667
668int fr_pair_cmp(fr_pair_t const *a, fr_pair_t const *b);
669
670int fr_pair_list_cmp(fr_pair_list_t const *a, fr_pair_list_t const *b) CC_HINT(nonnull);
671
672/* Filtering */
673void fr_pair_validate_debug(fr_pair_t const *failed[2]) CC_HINT(nonnull);
674
675bool fr_pair_validate(fr_pair_t const *failed[2], fr_pair_list_t *filter,
676 fr_pair_list_t *list) CC_HINT(nonnull(2,3));
677
678bool fr_pair_validate_relaxed(fr_pair_t const *failed[2], fr_pair_list_t *filter,
679 fr_pair_list_t *list) CC_HINT(nonnull(2,3));
680
681bool fr_pair_immutable(fr_pair_t const *vp) CC_HINT(nonnull);
682
683static inline CC_HINT(nonnull, always_inline)
685{
686 vp->vp_immutable = true;
687}
688
689static inline CC_HINT(nonnull, always_inline)
691{
692 vp->vp_immutable = false;
693}
694
695
696/* Lists */
697int fr_pair_list_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from);
698
699void fr_pair_list_steal(TALLOC_CTX *ctx, fr_pair_list_t *list);
700
702
703int fr_pair_list_copy_by_da(TALLOC_CTX *ctx, fr_pair_list_t *to,
704 fr_pair_list_t const *from, fr_dict_attr_t const *da, unsigned int count);
705
706int fr_pair_list_copy_by_ancestor(TALLOC_CTX *ctx, fr_pair_list_t *to,
707 fr_pair_list_t const *from,
708 fr_dict_attr_t const *parent_da) CC_HINT(nonnull);
709
710int fr_pair_sublist_copy(TALLOC_CTX *ctx, fr_pair_list_t *to,
711 fr_pair_list_t const *from,
712 fr_pair_t const *start, unsigned int count) CC_HINT(nonnull(2,3));
713
714#ifndef _PAIR_INLINE
715/** @hidecallergraph */
716void fr_pair_list_free(fr_pair_list_t *list) CC_HINT(nonnull);
717
719
720
721/** @hidecallergraph */
722bool fr_pair_list_empty(fr_pair_list_t const *list) CC_HINT(nonnull);
723
724size_t fr_pair_list_num_elements(fr_pair_list_t const *list) CC_HINT(nonnull);
725
727
729
730void fr_pair_list_sort(fr_pair_list_t *list, fr_cmp_t cmp) CC_HINT(nonnull);
731
733
735
736/** @hidecallergraph */
738
739/** @hidecallergraph */
740fr_pair_t *fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item) CC_HINT(nonnull(1));
741
742fr_pair_t *fr_pair_list_prev(fr_pair_list_t const *list, fr_pair_t const *item) CC_HINT(nonnull(1));
743
745#endif
746
747/** @name Pair to pair copying
748 *
749 * @{
750 */
752
753int fr_pair_value_copy(fr_pair_t *dst, fr_pair_t *src) CC_HINT(nonnull);
754/** @} */
755
756/** @name Assign and manipulate binary-unsafe C strings
757 *
758 * @{
759 */
761 char const *value, size_t len, fr_sbuff_unescape_rules_t const *erules,
762 bool tainted) CC_HINT(nonnull(1,2));
763
764int fr_pair_value_strdup(fr_pair_t *vp, char const *src, bool tainted) CC_HINT(nonnull);
765
766int fr_pair_value_strdup_shallow(fr_pair_t *vp, char const *src, bool tainted) CC_HINT(nonnull);
767
769
771 char const *fmt, ...) CC_HINT(nonnull) CC_HINT(format (printf, 2, 3));
772/** @} */
773
774/** @name Assign and manipulate binary-safe strings
775 *
776 * @{
777 */
778int fr_pair_value_bstr_alloc(fr_pair_t *vp, char **out, size_t size, bool tainted) CC_HINT(nonnull(1));
779
780int fr_pair_value_bstr_realloc(fr_pair_t *vp, char **out, size_t size) CC_HINT(nonnull(1));
781
782int fr_pair_value_bstrndup(fr_pair_t *vp, char const *src, size_t len, bool tainted) CC_HINT(nonnull(1));
783
784int fr_pair_value_bstrdup_buffer(fr_pair_t *vp, char const *src, bool tainted) CC_HINT(nonnull);
785
786int fr_pair_value_bstrndup_shallow(fr_pair_t *vp, char const *src, size_t len, bool tainted) CC_HINT(nonnull(1));
787
788int fr_pair_value_bstrdup_buffer_shallow(fr_pair_t *vp, char const *src, bool tainted) CC_HINT(nonnull);
789
790 /** @} */
791
792/** @name Assign and manipulate octets strings
793 *
794 * @{
795 */
796int fr_pair_value_mem_alloc(fr_pair_t *vp, uint8_t **out, size_t size, bool tainted) CC_HINT(nonnull(1));
797
798int fr_pair_value_mem_realloc(fr_pair_t *vp, uint8_t **out, size_t size) CC_HINT(nonnull(1));
799
800int fr_pair_value_memdup(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted) CC_HINT(nonnull(1));
801
802int fr_pair_value_memdup_buffer(fr_pair_t *vp, uint8_t const *src, bool tainted) CC_HINT(nonnull);
803
804int fr_pair_value_memdup_shallow(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted) CC_HINT(nonnull(1));
805
806int fr_pair_value_memdup_buffer_shallow(fr_pair_t *vp, uint8_t const *src, bool tainted) CC_HINT(nonnull);
807
808 /** @} */
809
810/** @name Enum functions
811 *
812 * @{
813 */
814char const *fr_pair_value_enum(fr_pair_t const *vp, char buff[static 20]) CC_HINT(nonnull);
815
817/** @} */
818
819/** @name Printing functions
820 *
821 * @{
822 */
824 fr_pair_t const *vp, fr_token_t quote) CC_HINT(nonnull);
825
826static inline fr_slen_t CC_HINT(nonnull(2,3))
827 fr_pair_aprint_value_quoted(TALLOC_CTX *ctx, char **out,
828 fr_pair_t const *vp, fr_token_t quote)
830
832 fr_pair_t const *vp) CC_HINT(nonnull(1,3));
833
835 fr_pair_t const *vp) CC_HINT(nonnull(1,3));
836
838
839static inline fr_slen_t CC_HINT(nonnull(2,4))
840 fr_pair_aprint(TALLOC_CTX *ctx, char **out, fr_dict_attr_t const *parent, fr_pair_t const *vp)
842
843static inline fr_slen_t CC_HINT(nonnull(2,4))
844 fr_pair_aprint_secure(TALLOC_CTX *ctx, char **out, fr_dict_attr_t const *parent, fr_pair_t const *vp)
846
847#define fr_pair_list_log(_log, _lvl, _list) _fr_pair_list_log(_log, _lvl, NULL, _list, __FILE__, __LINE__)
848void _fr_pair_list_log(fr_log_t const *log, int lvl, fr_pair_t *parent,
849 fr_pair_list_t const *list, char const *file, int line) CC_HINT(nonnull(1,4));
850
851void fr_pair_list_debug(FILE *fp, fr_pair_list_t const *list) CC_HINT(nonnull);
852void _fr_pair_list_debug(FILE *fp, int lvl, fr_pair_t *parent, fr_pair_list_t const *list)
853 CC_HINT(nonnull(1, 4));
854void fr_pair_debug(FILE *fp, fr_pair_t const *pair) CC_HINT(nonnull);
855
856/** @} */
857
859
860void fr_pair_list_afrom_box(TALLOC_CTX *ctx, fr_pair_list_t *out,
861 fr_dict_t const *dict, fr_value_box_t *box) CC_HINT(nonnull);
862
863/* Tokenization */
864typedef struct {
865 TALLOC_CTX *ctx; //!< to allocate VPs in
866 fr_dict_attr_t const *parent; //!< current attribute to allocate VPs in
867 fr_pair_list_t *list; //!< of VPs to add
869
870ssize_t fr_pair_ctx_afrom_str(fr_pair_ctx_t *pair_ctx, char const *in, size_t inlen) CC_HINT(nonnull);
871void fr_pair_ctx_reset(fr_pair_ctx_t *pair_ctx, fr_dict_t const *dict) CC_HINT(nonnull);
872
873void fr_fprintf_pair(FILE *fp, char const *msg, fr_pair_t const *vp);
874void fr_fprintf_pair_list(FILE *fp, fr_pair_list_t const *list);
875
876#undef _CONST
877#ifdef __cplusplus
878}
879#endif
int const char * file
Definition acutest.h:702
log_entry msg
Definition acutest.h:794
static int const char * fmt
Definition acutest.h:573
int const char int line
Definition acutest.h:702
#define DIAG_ON(_x)
Definition build.h:460
#define RCSIDH(h, id)
Definition build.h:486
#define DIAG_OFF(_x)
Definition build.h:459
void *(* fr_dcursor_iter_t)(fr_dcursor_t *cursor, void *to_eval, void *uctx)
Callback for implementing custom iterators.
Definition dcursor.h:51
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:207
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
Definition debug.h:131
static fr_slen_t in
Definition dict.h:848
Test enumeration values.
Definition dict_test.h:92
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
long int ssize_t
unsigned char uint8_t
ssize_t fr_slen_t
int8_t(* fr_cmp_t)(void const *a, void const *b)
Definition misc.h:38
#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:41
return count
Definition module.c:155
Definition log.h:96
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:772
#define FR_TLIST_TYPES(_name)
Define type specific wrapper structs for tlists.
Definition tlist.h:776
enum fr_token fr_token_t
static fr_slen_t head
Definition xlat.h:420
bool fr_pair_matches_da(void const *item, void const *uctx)
Evaluation function for matching if vp matches a given da.
Definition pair.c:3400
char const * fr_pair_value_enum(fr_pair_t const *vp, char buff[static 20])
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, unsigned int count)
Duplicate pairs in a list matching the specified da.
Definition pair.c:2409
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:961
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:2734
int fr_pair_list_cmp(fr_pair_list_t const *a, fr_pair_list_t const *b)
Determine equality of two lists.
Definition pair.c:2043
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:2968
fr_dlist_head_t * fr_pair_list_to_dlist(fr_pair_list_t const *list)
Get the dlist head from a pair list.
TALLOC_CTX * ctx
to allocate VPs in
Definition pair.h:865
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:2887
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:698
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:675
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:607
int fr_pair_sublist_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from, fr_pair_t const *start, unsigned int count))
Duplicate a list of pairs starting at a particular item.
Definition pair.c:2511
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:3068
int fr_pair_value_aprintf(fr_pair_t *vp, char const *fmt,...)
Print data into an "string" data type.
Definition pair.c:2702
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:1709
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:1369
void fr_fprintf_pair_list(FILE *fp, fr_pair_list_t const *list)
Definition pair.c:3536
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:2938
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:2201
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:244
fr_pair_t * fr_pair_find_by_child_num(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *parent, unsigned int attr))
Find the pair with the matching child attribute.
Definition pair.c:872
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:2319
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:2912
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:1402
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:383
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:247
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:1462
void fr_pair_validate_debug(fr_pair_t const *failed[2])
Write an error to the library errorbuff detailing the mismatch.
Definition pair.c:2089
int fr_pair_value_strdup(fr_pair_t *vp, char const *src, bool tainted)
Copy data into an "string" data type.
Definition pair.c:2638
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:551
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:2859
void fr_pair_init_null(fr_pair_t *vp)
Initialise fields in an fr_pair_t without assigning a da.
Definition pair.c:149
int8_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:1917
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:1685
fr_pair_list_t * fr_pair_parent_list(fr_pair_t const *vp)
Return a pointer to the parent pair list.
Definition pair.c:932
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.
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:898
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:1965
fr_pair_list_t * fr_pair_list_alloc(TALLOC_CTX *ctx)
Allocate a new pair list on the heap.
Definition pair.c:119
fr_pair_t * fr_pair_parent(fr_pair_t const *vp)
Return a pointer to the parent pair.
Definition pair.c:947
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
void _fr_pair_list_debug(FILE *fp, int lvl, fr_pair_t *parent, fr_pair_list_t const *list))
Print a list of attributes and enumv.
Definition pair_print.c:361
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:1165
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:1435
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:746
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:287
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:1312
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:2993
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:2814
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:2458
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:177
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:922
static fr_slen_t quote 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:117
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:2788
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:525
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:690
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:374
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:1343
#define _CONST
Definition pair.h:43
void fr_fprintf_pair(FILE *fp, char const *msg, fr_pair_t const *vp)
Definition pair.c:3544
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:169
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:2839
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:2276
void fr_pair_list_tainted(fr_pair_list_t *vps)
Mark up a list of VPs as tainted.
Definition pair.c:3373
void fr_pair_value_clear(fr_pair_t *vp)
Free/zero out value (or children) of a given VP.
Definition pair.c:2536
fr_pair_t * fr_pair_find_by_da_nested(fr_pair_list_t const *list, fr_pair_t const *prev, 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:775
static void fr_pair_set_immutable(fr_pair_t *vp)
Definition pair.h:684
fr_pair_list_t * list
of VPs to add
Definition pair.h:867
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:1822
static fr_slen_t vp
Definition pair.h:829
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:1804
int fr_pair_value_copy(fr_pair_t *dst, fr_pair_t *src)
Copy the value from one pair to another.
Definition pair.c:2566
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:1128
static bool fr_pair_list_nonnull_assert(fr_pair_list_t const *pair_list)
Definition pair.h:182
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:53
fr_pair_t * fr_pair_copy(TALLOC_CTX *ctx, fr_pair_t const *vp))
Copy a single valuepair.
Definition pair.c:493
int fr_pair_steal(TALLOC_CTX *ctx, fr_pair_t *vp)
Steal one VP.
Definition pair.c:526
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:2124
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_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:1296
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:1519
fr_pair_t * fr_pair_find_last_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da))
Find the last pair with a matching da.
Definition pair.c:722
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:1146
fr_pair_list_t * fr_pair_list_from_dlist(fr_dlist_head_t const *list)
Get the pair list head from a dlist.
ssize_t fr_pair_ctx_afrom_str(fr_pair_ctx_t *pair_ctx, char const *in, size_t inlen)
Parse a pair context from a string.
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:2681
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:471
#define fr_pair_dcursor_init(_cursor, _list)
Initialises a special dcursor with callbacks that will maintain the attr sublists correctly.
Definition pair.h:589
void _fr_pair_list_log(fr_log_t const *log, int lvl, fr_pair_t *parent, fr_pair_list_t const *list, char const *file, int line))
Print a list of attributes and enumv.
Definition pair_print.c:311
fr_dict_attr_t const * parent
current attribute to allocate VPs in
Definition pair.h:866
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:1592
void fr_pair_list_init(fr_pair_list_t *head)
Initialise a pair list header.
Definition pair.c:46
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:318
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:2759
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:1249
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:3496
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:1043
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:2300
fr_pair_t * fr_pair_afrom_da_depth_nested(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_attr_t const *da, int start)
Create a pair (and all intermediate parents), and append it to the list.
Definition pair.c:412
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:574
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:1489
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:598
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:176
int8_t fr_pair_cmp_by_da(void const *a, void const *b)
Order attributes by their da, and tag.
Definition pair.c:1840
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:3013
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:2662
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:242
static fr_slen_t parent
Definition pair.h:841
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:1108
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:2354
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:375
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_slen_t data
Definition value.h:1291
static size_t char fr_sbuff_t size_t inlen
Definition value.h:1023
int nonnull(2, 5))
static size_t char ** out
Definition value.h:1023