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: c42853ca715302f173b1151393fa83b325521187 $")
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#ifdef WITH_VERIFY_PTR
109 char const *filename; //!< Where the pair was defined
110 int line; //!< Line number where the attribute was defined.
111#endif
112};
113
114#define vp_strvalue data.vb_strvalue
115#define vp_octets data.vb_octets
116#define vp_ptr data.datum.ptr //!< Either octets or strvalue
117#define vp_length data.vb_length
118
119#define vp_ipv4addr data.vb_ip.addr.v4.s_addr
120#define vp_ipv6addr data.vb_ip.addr.v6.s6_addr
121#define vp_ip data.vb_ip
122#define vp_ifid data.vb_ifid
123#define vp_ether data.vb_ether
124
125#define vp_bool data.datum.boolean
126#define vp_uint8 data.vb_uint8
127#define vp_uint16 data.vb_uint16
128#define vp_uint32 data.vb_uint32
129#define vp_uint64 data.vb_uint64
130
131#define vp_int8 data.vb_int8
132#define vp_int16 data.vb_int16
133#define vp_int32 data.vb_int32
134#define vp_int64 data.vb_int64
135
136#define vp_float32 data.vb_float32
137#define vp_float64 data.vb_float64
138
139#define vp_attr data.vb_attr
140
141#define vp_date data.vb_date
142#define vp_time_delta data.vb_time_delta
143
144#define vp_group children
145
146#define vp_size data.datum.size
147#define vp_filter data.datum.filter
148
149#define vp_type data.type
150#define vp_tainted data.tainted
151#define vp_immutable data.immutable
152#define vp_edit data.edit
153#define vp_raw da->flags.is_raw
154
155#define ATTRIBUTE_EQ(_x, _y) ((_x && _y) && (_x->da == _y->da))
156
157/** If WITH_VERIFY_PTR is defined, we perform runtime checks to ensure the fr_pair_t are sane
158 *
159 */
160#ifdef WITH_VERIFY_PTR
161void fr_pair_verify(char const *file, int line, fr_dict_attr_t const *parent, fr_pair_list_t const *list, fr_pair_t const *vp) 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) CC_HINT(nonnull(4));
165
166# define PAIR_VERIFY(_x) fr_pair_verify(__FILE__, __LINE__, NULL, NULL, _x)
167# define PAIR_VERIFY_WITH_LIST(_l, _x) fr_pair_verify(__FILE__, __LINE__, NULL, _l, _x)
168# define PAIR_LIST_VERIFY(_x) fr_pair_list_verify(__FILE__, __LINE__, NULL, _x)
169# define PAIR_VERIFY_WITH_PARENT_VP(_p, _x) fr_pair_verify(__FILE__, __LINE__, (_p)->da, &(_p)->vp_group, _x)
170# define PAIR_VERIFY_WITH_PARENT_DA(_p, _x) fr_pair_verify(__FILE__, __LINE__, _p, NULL, _x)
171
172#define PAIR_ALLOCED(_x) do { (_x)->filename = __FILE__; (_x)->line = __LINE__; } while (0)
173#else
174DIAG_OFF(nonnull-compare)
175/** Wrapper function to defeat nonnull checks
176 *
177 * We may sprinkle PAIR_VERIFY and PAIR_LIST_VERIFY in functions which
178 * have their pair argument marked up as nonnull.
179 *
180 * This would usually generate errors when WITH_VERIFY_PTR is not
181 * defined, as the assert macros check for an arguments NULLness.
182 *
183 * This function wraps the assert but has nonnull-compare disabled
184 * meaning a warning won't be emitted.
185 */
186static inline bool fr_pair_nonnull_assert(fr_pair_t const *vp)
187{
188 return fr_cond_assert(vp);
189}
190
192{
194}
195DIAG_ON(nonnull-compare)
196
197/*
198 * Even if were building without WITH_VERIFY_PTR
199 * the pointer must not be NULL when these various macros are used
200 * so we can add some sneaky soft asserts.
201 */
202# define PAIR_VERIFY(_x) fr_pair_nonnull_assert(_x)
203# define PAIR_VERIFY_WITH_LIST(_l, _x) fr_pair_list_nonnull_assert(_l); \
204 fr_pair_nonnull_assert(_x)
205# define PAIR_LIST_VERIFY(_x) fr_pair_list_nonnull_assert(_x)
206# define PAIR_VERIFY_WITH_PARENT_VP(_p, _x) fr_pair_list_nonnull_assert(_p); \
207 fr_pair_list_nonnull_assert(_x)
208# define PAIR_VERIFY_WITH_PARENT_DA(_p, _x) fr_pair_list_nonnull_assert(_x)
209# define PAIR_ALLOCED(_x) fr_pair_nonnull_assert(_x)
210#endif
211
212
213#ifdef TEST_CHECK
214/** Macro for use in acutest tests
215 */
216#define TEST_CHECK_PAIR(_got, _exp) \
217do { \
218 fr_pair_t const *_our_got = (_got); \
219 fr_pair_t const *_our_exp = (_exp); \
220 TEST_CHECK_(_our_exp == _our_got, "%s", #_got); \
221 if (_our_exp) { \
222 TEST_MSG("Expected pair : %s - %p (%s)", (_our_exp)->da->name, _our_exp, talloc_get_name(_our_exp)); \
223 } else { \
224 TEST_MSG("Expected pair : NULL"); \
225 } \
226 if (_our_got) { \
227 TEST_MSG("Got pair : %s - %p (%s)", (_our_got)->da->name, _our_got, talloc_get_name(_our_got)); \
228 } else { \
229 TEST_MSG("Got Pair : NULL"); \
230 } \
231} while(0)
232
233#define TEST_CHECK_PAIR_NEQ(_got, _neq) \
234do { \
235 fr_pair_t const *_our_got = (_got); \
236 fr_pair_t const *_our_neq = (_neq); \
237 TEST_CHECK_(_our_got != _our_neq, "%s", #_got); \
238 if (_our_neq) { \
239 TEST_MSG("Pair must not equal : %s - %p (%s)", (_our_neq)->da->name, _our_neq, talloc_get_name(_our_neq)); \
240 } else { \
241 TEST_MSG("Pair must not equal : NULL"); \
242 } \
243} while(0)
244#endif
245
246/*
247 * Helper macros for adding pairs to lists and assigning a value to them
248 */
249
250/** Check a pair's data type matches the DA data type
251 *
252 * @param[in] vp to check consistency of.
253 * @return
254 * - true for match
255 * - false for error
256 */
258{
259 if (vp->vp_type == vp->da->type) return true;
260
261 fr_strerror_printf("fr_pair_t attribute %p \"%s\" data type (%s) does not match da type (%s)",
262 vp->da, vp->da->name,
263 fr_table_str_by_value(fr_type_table, vp->vp_type, "invalid"),
264 fr_table_str_by_value(fr_type_table, vp->da->type, "invalid"));
265 return false;
266}
267
268/** Iterate over the contents of a #fr_pair_list_t
269 *
270 * The iteration variable can be safely removed from the list at each pass.
271 *
272 * @param[in] _list_head to iterate over.
273 * @param[in] _iter Name of iteration variable.
274 * Will be declared in the scope of the loop.
275 */
276#define fr_pair_list_foreach(_list_head, _iter) \
277 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))
278
279/** Iterate over the leaf nodes of a #fr_pair_list_t
280 *
281 * The iteration variable CANNOT be modified. This is a read-only operation.
282 *
283 * @param[in] _list_head to iterate over.
284 * @param[in] _iter Name of iteration variable.
285 * Will be declared in the scope of the loop.
286 */
287#define fr_pair_list_foreach_leaf(_list_head, _iter) \
288 for (fr_pair_t *_iter = fr_pair_list_iter_leaf(_list_head, NULL); _iter != NULL; _iter = fr_pair_list_iter_leaf(_list_head, _iter))
289
290/** Append a pair to a list, assigning its value.
291 *
292 * Version for simple C data types
293 *
294 * @param[in] _ctx to allocate the pair in
295 * @param[out] _vp the allocated pair
296 * @param[in] _list to append the pair to
297 * @param[in] _attr to use when creating pair
298 * @param[in] _val to assign to the pair
299 * @param[in] _tainted does the value come from a trusted source
300 */
301#define fr_pair_list_append_by_da(_ctx, _vp, _list, _attr, _val, _tainted) \
302do { \
303 _vp = NULL; \
304 if (fr_pair_append_by_da(_ctx, &_vp, _list, _attr) < 0) break; \
305 fr_value_box(&_vp->data, _val, _tainted); \
306 if (!vp_da_data_type_check(_vp)) { \
307 fr_pair_delete(_list, _vp); \
308 _vp = NULL; \
309 } \
310} while (0)
311
312/** Append a pair to a list, assigning its value.
313 *
314 * Version for char* and uint8_t*
315 *
316 * @param[in] _ctx to allocate the pair in
317 * @param[out] _vp the allocated pair
318 * @param[in] _list to append the pair to
319 * @param[in] _attr to use when creating pair
320 * @param[in] _val to assign to the pair
321 * @param[in] _len of value
322 * @param[in] _tainted does the value come from a trusted source
323 */
324#define fr_pair_list_append_by_da_len(_ctx, _vp, _list, _attr, _val, _len, _tainted) \
325do { \
326 _vp = NULL; \
327 if (fr_pair_append_by_da(_ctx, &_vp, _list, _attr) < 0) break; \
328 fr_value_box_len(_vp, &_vp->data, _val, _len, _tainted); \
329 if (!vp_da_data_type_check(_vp)) { \
330 fr_pair_delete(_list, _vp); \
331 _vp = NULL; \
332 } \
333} while (0)
334
335#define fr_pair_list_append_by_da_parent(_ctx, _vp, _list, _attr, _val, _tainted) \
336do { \
337 _vp = NULL; \
338 if (fr_pair_append_by_da_parent(_ctx, &_vp, _list, _attr) < 0) break; \
339 fr_value_box(&_vp->data, _val, _tainted); \
340 if (!vp_da_data_type_check(_vp)) { \
341 fr_pair_delete(_list, _vp); \
342 _vp = NULL; \
343 } \
344} while (0)
345
346#define fr_pair_list_append_by_da_parent_len(_ctx, _vp, _list, _attr, _val, _len, _tainted) \
347do { \
348 _vp = NULL; \
349 if (fr_pair_append_by_da_parent(_ctx, &vp, _list, _attr) < 0) break; \
350 fr_value_box_len(_vp, &_vp->data, _val, _len, _tainted); \
351 if (!vp_da_data_type_check(_vp)) { \
352 fr_pair_delete(_list, _vp); \
353 _vp = NULL; \
354 } \
355} while (0)
356
357/** Prepend a pair to a list, assigning its value
358 *
359 * Version for simple C data types
360 *
361 * @param[in] _ctx to allocate the pair in
362 * @param[out] _vp the allocated pair
363 * @param[in] _list to prepend the pair to
364 * @param[in] _attr to use when creating pair
365 * @param[in] _val to assign to the pair
366 * @param[in] _tainted does the value come from a trusted source
367 */
368#define fr_pair_list_prepend_by_da(_ctx, _vp, _list, _attr, _val, _tainted) \
369do { \
370 _vp = NULL; \
371 if (fr_pair_prepend_by_da(_ctx, &_vp, _list, _attr) < 0) break; \
372 fr_value_box(&_vp->data, _val, _tainted); \
373 if (!vp_da_data_type_check(_vp)) { \
374 fr_pair_delete(_list, _vp); \
375 _vp = NULL; \
376 } \
377} while (0)
378
379/** Prepend a pair to a list, assigning its value.
380 *
381 * Version for char* and uint8_t*
382 *
383 * @param[in] _ctx to allocate the pair in
384 * @param[out] _vp the allocated pair
385 * @param[in] _list to prepend the pair to
386 * @param[in] _attr to use when creating pair
387 * @param[in] _val to assign to the pair
388 * @param[in] _len of value
389 * @param[in] _tainted does the value come from a trusted source
390 */
391#define fr_pair_list_prepend_by_da_len(_ctx, _vp, _list, _attr, _val, _len, _tainted) \
392do { \
393 _vp = NULL; \
394 if (fr_pair_prepend_by_da(_ctx, &_vp, _list, _attr) < 0) break; \
395 fr_value_box_len(_vp, &_vp->data, _val, _len, _tainted); \
396 if (!vp_da_data_type_check(_vp)) { \
397 fr_pair_delete(_list, _vp); \
398 _vp = NULL; \
399 } \
400} while (0)
401
402/** Replace a pair in a list, assigning its value
403 *
404 * Version for simple C data types.
405 * If the pair does not already exist, a new one is allocated.
406 *
407 * @param[in] _ctx to allocate the pair in
408 * @param[out] _vp the allocated pair
409 * @param[in] _list to append the pair to
410 * @param[in] _attr to use when creating pair
411 * @param[in] _val to assign to the pair
412 * @param[in] _tainted does the value come from a trusted source
413 */
414#define fr_pair_list_replace_by_da(_ctx, _vp, _list, _attr, _val, _tainted) \
415do { \
416 fr_pair_update_by_da(_ctx, _vp, _list, _attr, 0); \
417 if (!vp) break; \
418 fr_value_box(&_vp->data, _val, _tainted); \
419 if (!vp_da_data_type_check(_vp)) { \
420 fr_pair_delete(_list, _vp); \
421 _vp = NULL; \
422 } \
423} while (0)
424
425/** Replace a pair in a list, assigning its value
426 *
427 * Version for char* and uint8_t*
428 * If the pair does not already exist, a new one is allocated.
429 *
430 * @param[in] _ctx to allocate the pair in
431 * @param[out] _vp the allocated pair
432 * @param[in] _list to append the pair to
433 * @param[in] _attr to use when creating pair
434 * @param[in] _val to assign to the pair
435 * @param[in] _len of value
436 * @param[in] _tainted does the value come from a trusted source
437 */
438#define fr_pair_list_replace_by_da_len(_ctx, _vp, _list, _attr, _val, _len, _tainted) \
439do { \
440 fr_pair_t *oldvp = fr_pair_find_by_da(_list, NULL, _attr); \
441 fr_pair_list_append_by_da_len(_ctx, _vp_, _list, _attr, _val, _len, _tainted) \
442 if (!vp_da_data_type_check(_vp)) { \
443 fr_pair_delete(_list, _vp); \
444 _vp = NULL; \
445 } \
446 if (!_vp) break; \
447 if (oldvp) fr_pair_delete(_list, oldvp); \
448} while (0)
449
450/* Initialisation */
451/** @hidecallergraph */
453
454void fr_pair_init_null(fr_pair_t *vp) CC_HINT(nonnull);
455
456/* Allocation and management */
457fr_pair_t *fr_pair_alloc_null(TALLOC_CTX *ctx) CC_HINT(warn_unused_result);
458
459fr_pair_list_t *fr_pair_list_alloc(TALLOC_CTX *ctx) CC_HINT(warn_unused_result);
460
461fr_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));
462
463/** @hidecallergraph */
464fr_pair_t *fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da) CC_HINT(warn_unused_result) CC_HINT(nonnull(2));
465
467 CC_HINT(nonnull(2, 3));
468
469fr_pair_t *fr_pair_afrom_child_num(TALLOC_CTX *ctx, fr_dict_attr_t const *parent, unsigned int attr) CC_HINT(warn_unused_result);
470
471fr_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));
472
473fr_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));
474
475fr_pair_t *fr_pair_copy(TALLOC_CTX *ctx, fr_pair_t const *vp) CC_HINT(nonnull(2)) CC_HINT(warn_unused_result);
476
477int fr_pair_steal(TALLOC_CTX *ctx, fr_pair_t *vp) CC_HINT(nonnull);
478
479int fr_pair_steal_append(TALLOC_CTX *nctx, fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull);
480
481int fr_pair_steal_prepend(TALLOC_CTX *nctx, fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull);
482
483/* Searching and list modification */
484int fr_pair_raw_afrom_pair(fr_pair_t *vp, uint8_t const *data, size_t data_len) CC_HINT(nonnull);
485
486bool fr_pair_matches_da(void const *item, void const *uctx) CC_HINT(nonnull);
487
488/** @hidecallergraph */
489unsigned int fr_pair_count_by_da(fr_pair_list_t const *list, fr_dict_attr_t const *da)
490 CC_HINT(nonnull);
491
492/** @hidecallergraph */
494 fr_pair_t const *prev, fr_dict_attr_t const *da) CC_HINT(nonnull(1,3));
495
497 fr_dict_attr_t const *da, unsigned int idx) CC_HINT(nonnull);
498
500 fr_dict_attr_t const *da) CC_HINT(nonnull(1,3));
501
503 fr_pair_t const *prev, fr_dict_attr_t const *da) CC_HINT(nonnull(1,3));
504
506 fr_dict_attr_t const *parent, unsigned int attr) CC_HINT(nonnull(1,3));
507
509 fr_dict_attr_t const *parent, unsigned int attr,
510 unsigned int idx) CC_HINT(nonnull);
511
512/** @hidecallergraph */
513int fr_pair_append(fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull);
514
516
517int fr_pair_insert_after(fr_pair_list_t *list, fr_pair_t *pos, fr_pair_t *to_add) CC_HINT(nonnull(1,3));
518
519int fr_pair_insert_before(fr_pair_list_t *list, fr_pair_t *pos, fr_pair_t *to_add) CC_HINT(nonnull(1,3));
520
521void fr_pair_replace(fr_pair_list_t *list, fr_pair_t *to_replace, fr_pair_t *vp) CC_HINT(nonnull);
522
524 fr_dict_attr_t const *parent, unsigned int attr) CC_HINT(nonnull);
525
526int fr_pair_append_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list,
527 fr_dict_attr_t const *da) CC_HINT(nonnull(3,4));
528
529int fr_pair_prepend_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_append_by_da_parent(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
536 fr_dict_attr_t const *da) CC_HINT(nonnull(1,3));
537
538static 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,
539 fr_dict_attr_t const *da)
540{
541 fr_pair_t *vp;
542
543 vp = fr_pair_find_by_da(list, NULL, da);
544 if (vp) {
545 *out = vp;
546 return 0;
547 }
548
549 return fr_pair_append_by_da(ctx, out, list, da);
550}
551
552
554
556
557int fr_pair_delete(fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull);
558
559/* functions for FR_TYPE_STRUCTURAL */
561
563
565
567
569
570/** Initialises a special dcursor with callbacks that will maintain the attr sublists correctly
571 *
572 * @note This is the only way to use a dcursor in non-const mode with fr_pair_list_t.
573 *
574 * @param[out] _cursor to initialise.
575 * @param[in] _list to iterate over.
576 * @param[in] _iter Iterator to use when filtering pairs.
577 * @param[in] _uctx To pass to iterator.
578 * @return
579 * - NULL if src does not point to any items.
580 * - The first pair in the list.
581 */
582#define fr_pair_dcursor_iter_init(_cursor, _list, _iter, _uctx) \
583 _fr_pair_dcursor_iter_init(_cursor, \
584 _list, \
585 _iter, \
586 _uctx, \
587 IS_CONST(fr_pair_list_t *, _list))
589 fr_dcursor_iter_t iter, void const *uctx,
590 bool is_const) CC_HINT(nonnull);
591
592/** Initialises a special dcursor with callbacks that will maintain the attr sublists correctly
593 *
594 * @note This is the only way to use a dcursor in non-const mode with fr_pair_list_t.
595 *
596 * @param[out] _cursor to initialise.
597 * @param[in] _list to iterate over.
598 * @return
599 * - NULL if src does not point to any items.
600 * - The first pair in the list.
601 */
602#define fr_pair_dcursor_init(_cursor, _list) \
603 _fr_pair_dcursor_init(_cursor, \
604 _list, \
605 IS_CONST(fr_pair_list_t *, _list))
607 bool is_const) CC_HINT(nonnull);
608
609/** Initializes a child dcursor from a parent cursor, with an iteration function.
610 *
611 * @note This is the only way to use a dcursor in non-const mode with fr_pair_list_t.
612 *
613 * @param[out] cursor to initialise.
614 * @param[in] list to iterate over.
615 * @param[in] parent parent cursor to take the iterator from
616 * @return
617 * - NULL if src does not point to any items.
618 * - The first pair in the list.
619 */
621{
622 fr_pair_t *vp = fr_pair_dcursor_init(cursor, list);
623
625 return vp;
626}
627
628/** Initialise a cursor that will return only attributes matching the specified #fr_dict_attr_t
629 *
630 * @param[in] _cursor to initialise.
631 * @param[in] _list to iterate over.
632 * @param[in] _da to search for.
633 * @return
634 * - The first matching pair.
635 * - NULL if no pairs match.
636 */
637#define fr_pair_dcursor_by_da_init(_cursor, _list, _da) \
638 _fr_pair_dcursor_by_da_init(_cursor, \
639 _list, \
640 _da, \
641 IS_CONST(fr_pair_list_t *, _list))
643 fr_pair_list_t const *list, fr_dict_attr_t const *da,
644 bool is_const) CC_HINT(nonnull);
645
646/** Initialise a cursor that will return only attributes descended from the specified #fr_dict_attr_t
647 *
648 * @param[in] _cursor to initialise.
649 * @param[in] _list to iterate over.
650 * @param[in] _da who's decentness to search for.
651 * @return
652 * - The first matching pair.
653 * - NULL if no pairs match.
654 */
655#define fr_pair_dcursor_by_ancestor_init(_cursor, _list, _da) \
656 _fr_pair_dcursor_by_ancestor_init(_cursor, \
657 _list, \
658 _da, \
659 IS_CONST(fr_pair_list_t *, _list))
661 fr_pair_list_t const *list, fr_dict_attr_t const *da,
662 bool is_const) CC_HINT(nonnull);
663
665
667
668/** Compare two attributes using and operator.
669 *
670 * @return
671 * - 1 if equal.
672 * - 0 if not equal.
673 * - -1 on failure.
674 */
675#define fr_pair_cmp_op(_op, _a, _b) fr_value_box_cmp_op(_op, &_a->data, &_b->data)
676
677int8_t fr_pair_cmp_by_da(void const *a, void const *b);
678
679int8_t fr_pair_cmp_by_parent_num(void const *a, void const *b);
680
681int fr_pair_cmp(fr_pair_t const *a, fr_pair_t const *b);
682
683int fr_pair_list_cmp(fr_pair_list_t const *a, fr_pair_list_t const *b) CC_HINT(nonnull);
684
685/* Filtering */
686void fr_pair_validate_debug(fr_pair_t const *failed[2]) CC_HINT(nonnull);
687
688bool fr_pair_validate(fr_pair_t const *failed[2], fr_pair_list_t *filter,
689 fr_pair_list_t *list) CC_HINT(nonnull(2,3));
690
691bool fr_pair_validate_relaxed(fr_pair_t const *failed[2], fr_pair_list_t *filter,
692 fr_pair_list_t *list) CC_HINT(nonnull(2,3));
693
694bool fr_pair_immutable(fr_pair_t const *vp) CC_HINT(nonnull);
695
696static inline CC_HINT(nonnull, always_inline)
698{
699 vp->vp_immutable = true;
700}
701
702static inline CC_HINT(nonnull, always_inline)
704{
705 vp->vp_immutable = false;
706}
707
708
709/* Lists */
710int fr_pair_list_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from);
711
712void fr_pair_list_steal(TALLOC_CTX *ctx, fr_pair_list_t *list);
713
715
716int fr_pair_list_copy_by_da(TALLOC_CTX *ctx, fr_pair_list_t *to,
717 fr_pair_list_t const *from, fr_dict_attr_t const *da, unsigned int count);
718
719int fr_pair_list_copy_by_ancestor(TALLOC_CTX *ctx, fr_pair_list_t *to,
720 fr_pair_list_t const *from,
721 fr_dict_attr_t const *parent_da) CC_HINT(nonnull);
722
723int fr_pair_sublist_copy(TALLOC_CTX *ctx, fr_pair_list_t *to,
724 fr_pair_list_t const *from,
725 fr_pair_t const *start, unsigned int count) CC_HINT(nonnull(2,3));
726
727#ifndef _PAIR_INLINE
728/** @hidecallergraph */
729void fr_pair_list_free(fr_pair_list_t *list) CC_HINT(nonnull);
730
732
733
734/** @hidecallergraph */
735bool fr_pair_list_empty(fr_pair_list_t const *list) CC_HINT(nonnull);
736
737size_t fr_pair_list_num_elements(fr_pair_list_t const *list) CC_HINT(nonnull);
738
740
742
743void fr_pair_list_sort(fr_pair_list_t *list, fr_cmp_t cmp) CC_HINT(nonnull);
744
746
748
749/** @hidecallergraph */
751
752/** @hidecallergraph */
753fr_pair_t *fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item) CC_HINT(nonnull(1));
754
755fr_pair_t *fr_pair_list_prev(fr_pair_list_t const *list, fr_pair_t const *item) CC_HINT(nonnull(1));
756
758#endif
759
760/** @name Pair to pair copying
761 *
762 * @{
763 */
765
766int fr_pair_value_copy(fr_pair_t *dst, fr_pair_t *src) CC_HINT(nonnull);
767/** @} */
768
769/** @name Assign and manipulate binary-unsafe C strings
770 *
771 * @{
772 */
774 char const *value, size_t len, fr_sbuff_unescape_rules_t const *erules,
775 bool tainted) CC_HINT(nonnull(1,2));
776
777int fr_pair_value_strdup(fr_pair_t *vp, char const *src, bool tainted) CC_HINT(nonnull);
778
779int fr_pair_value_strdup_shallow(fr_pair_t *vp, char const *src, bool tainted) CC_HINT(nonnull);
780
782
784 char const *fmt, ...) CC_HINT(nonnull) CC_HINT(format (printf, 2, 3));
785/** @} */
786
787/** @name Assign and manipulate binary-safe strings
788 *
789 * @{
790 */
791int fr_pair_value_bstr_alloc(fr_pair_t *vp, char **out, size_t size, bool tainted) CC_HINT(nonnull(1));
792
793int fr_pair_value_bstr_realloc(fr_pair_t *vp, char **out, size_t size) CC_HINT(nonnull(1));
794
795int fr_pair_value_bstrndup(fr_pair_t *vp, char const *src, size_t len, bool tainted) CC_HINT(nonnull(1));
796
797int fr_pair_value_bstrdup_buffer(fr_pair_t *vp, char const *src, bool tainted) CC_HINT(nonnull);
798
799int fr_pair_value_bstrndup_shallow(fr_pair_t *vp, char const *src, size_t len, bool tainted) CC_HINT(nonnull(1));
800
801int fr_pair_value_bstrdup_buffer_shallow(fr_pair_t *vp, char const *src, bool tainted) CC_HINT(nonnull);
802
803 /** @} */
804
805/** @name Assign and manipulate octets strings
806 *
807 * @{
808 */
809int fr_pair_value_mem_alloc(fr_pair_t *vp, uint8_t **out, size_t size, bool tainted) CC_HINT(nonnull(1));
810
811int fr_pair_value_mem_realloc(fr_pair_t *vp, uint8_t **out, size_t size) CC_HINT(nonnull(1));
812
813int fr_pair_value_memdup(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted) CC_HINT(nonnull(1));
814
815int fr_pair_value_memdup_buffer(fr_pair_t *vp, uint8_t const *src, bool tainted) CC_HINT(nonnull);
816
817int fr_pair_value_memdup_shallow(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted) CC_HINT(nonnull(1));
818
819int fr_pair_value_memdup_buffer_shallow(fr_pair_t *vp, uint8_t const *src, bool tainted) CC_HINT(nonnull);
820
821 /** @} */
822
823/** @name Enum functions
824 *
825 * @{
826 */
827char const *fr_pair_value_enum(fr_pair_t const *vp, char buff[static 20]) CC_HINT(nonnull);
828
830/** @} */
831
832/** @name Printing functions
833 *
834 * @{
835 */
837 fr_pair_t const *vp, fr_token_t quote) CC_HINT(nonnull);
838
839static inline fr_slen_t CC_HINT(nonnull(2,3))
840 fr_pair_aprint_value_quoted(TALLOC_CTX *ctx, char **out,
841 fr_pair_t const *vp, fr_token_t quote)
843
845 fr_pair_t const *vp) CC_HINT(nonnull(1,3));
846
848 fr_pair_t const *vp) CC_HINT(nonnull(1,3));
849
851
852static inline fr_slen_t CC_HINT(nonnull(2,4))
853 fr_pair_aprint(TALLOC_CTX *ctx, char **out, fr_dict_attr_t const *parent, fr_pair_t const *vp)
855
856static inline fr_slen_t CC_HINT(nonnull(2,4))
857 fr_pair_aprint_secure(TALLOC_CTX *ctx, char **out, fr_dict_attr_t const *parent, fr_pair_t const *vp)
859
860#define fr_pair_list_log(_log, _lvl, _list) _fr_pair_list_log(_log, _lvl, NULL, _list, __FILE__, __LINE__)
861void _fr_pair_list_log(fr_log_t const *log, int lvl, fr_pair_t *parent,
862 fr_pair_list_t const *list, char const *file, int line) CC_HINT(nonnull(1,4));
863
864void fr_pair_list_debug(FILE *fp, fr_pair_list_t const *list) CC_HINT(nonnull);
865void _fr_pair_list_debug(FILE *fp, int lvl, fr_pair_t *parent, fr_pair_list_t const *list)
866 CC_HINT(nonnull(1, 4));
867void fr_pair_debug(FILE *fp, fr_pair_t const *pair) CC_HINT(nonnull);
868
869/** @} */
870
872
873void fr_pair_list_afrom_box(TALLOC_CTX *ctx, fr_pair_list_t *out,
874 fr_dict_t const *dict, fr_value_box_t *box) CC_HINT(nonnull);
875
876/* Tokenization */
877typedef struct {
878 TALLOC_CTX *ctx; //!< to allocate VPs in
879 fr_dict_attr_t const *parent; //!< current attribute to allocate VPs in
880 fr_pair_list_t *list; //!< of VPs to add
882
883ssize_t fr_pair_ctx_afrom_str(fr_pair_ctx_t *pair_ctx, char const *in, size_t inlen) CC_HINT(nonnull);
884void fr_pair_ctx_reset(fr_pair_ctx_t *pair_ctx, fr_dict_t const *dict) CC_HINT(nonnull);
885
886void fr_fprintf_pair(FILE *fp, char const *msg, fr_pair_t const *vp);
887void fr_fprintf_pair_list(FILE *fp, fr_pair_list_t const *list);
888
889#undef _CONST
890#ifdef __cplusplus
891}
892#endif
int const char * file
Definition acutest.h:704
log_entry msg
Definition acutest.h:796
static int const char * fmt
Definition acutest.h:575
int const char int line
Definition acutest.h:704
#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:870
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:3427
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:2416
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:966
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:2741
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:2050
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:2975
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:878
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:2894
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:416
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:703
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:680
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:620
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:2518
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:3075
int fr_pair_value_aprintf(fr_pair_t *vp, char const *fmt,...)
Print data into an "string" data type.
Definition pair.c:2709
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:1716
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:1374
void fr_fprintf_pair_list(FILE *fp, fr_pair_list_t const *list)
Definition pair_print.c:438
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:2945
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:2208
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:257
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:877
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:2326
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:2919
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:1407
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:404
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:248
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:1467
void fr_pair_validate_debug(fr_pair_t const *failed[2])
Write an error to the library errorbuff detailing the mismatch.
Definition pair.c:2096
int fr_pair_value_strdup(fr_pair_t *vp, char const *src, bool tainted)
Copy data into an "string" data type.
Definition pair.c:2645
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:556
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:2866
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:1924
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:1692
fr_pair_list_t * fr_pair_parent_list(fr_pair_t const *vp)
Return a pointer to the parent pair list.
Definition pair.c:937
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:903
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:1972
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:952
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:380
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:1170
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:1440
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:751
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:289
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:1317
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:3000
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:2821
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:2465
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:186
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:927
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:136
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:2795
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:538
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:703
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:395
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:1348
#define _CONST
Definition pair.h:43
void fr_fprintf_pair(FILE *fp, char const *msg, fr_pair_t const *vp)
Definition pair_print.c:446
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:2846
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:2283
void fr_pair_list_tainted(fr_pair_list_t *vps)
Mark up a list of VPs as tainted.
Definition pair.c:3400
void fr_pair_value_clear(fr_pair_t *vp)
Free/zero out value (or children) of a given VP.
Definition pair.c:2543
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:780
static void fr_pair_set_immutable(fr_pair_t *vp)
Definition pair.h:697
fr_pair_list_t * list
of VPs to add
Definition pair.h:880
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:1829
static fr_slen_t vp
Definition pair.h:842
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:1811
int fr_pair_value_copy(fr_pair_t *dst, fr_pair_t *src)
Copy the value from one pair to another.
Definition pair.c:2573
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:1133
static bool fr_pair_list_nonnull_assert(fr_pair_list_t const *pair_list)
Definition pair.h:191
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:497
int fr_pair_steal(TALLOC_CTX *ctx, fr_pair_t *vp)
Steal one VP.
Definition pair.c:531
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:2131
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:1301
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:1524
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:727
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:1151
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:2688
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:474
#define fr_pair_dcursor_init(_cursor, _list)
Initialises a special dcursor with callbacks that will maintain the attr sublists correctly.
Definition pair.h:602
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:328
fr_dict_attr_t const * parent
current attribute to allocate VPs in
Definition pair.h:879
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:1598
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: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:2766
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:1254
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:3512
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:1048
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:2307
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:579
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:1494
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:603
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:193
int8_t fr_pair_cmp_by_da(void const *a, void const *b)
Order attributes by their da, and tag.
Definition pair.c:1847
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:3020
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:2669
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:259
static fr_slen_t parent
Definition pair.h:854
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:1113
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:2361
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:378
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:1322
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