The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
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  */
24 RCSIDH(dpair_h, "$Id: a1aac7ea57dfd2f707225714d8fb3b407bd51d24 $")
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
33 extern "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 
48 typedef struct value_pair_s fr_pair_t;
49 
50 FR_TLIST_TYPES(fr_pair_order_list)
51 
52 typedef 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  */
68 struct value_pair_s {
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_date data.vb_date
135 #define vp_time_delta data.vb_time_delta
136 
137 #define vp_group children
138 
139 #define vp_size data.datum.size
140 #define vp_filter data.datum.filter
141 
142 #define vp_type data.type
143 #define vp_tainted data.tainted
144 #define vp_immutable data.immutable
145 #define vp_edit data.edit
146 #define vp_raw da->flags.is_raw
147 
148 #define ATTRIBUTE_EQ(_x, _y) ((_x && _y) && (_x->da == _y->da))
149 
150 /** If WITH_VERIFY_PTR is defined, we perform runtime checks to ensure the fr_pair_t are sane
151  *
152  */
153 #ifdef WITH_VERIFY_PTR
154 void fr_pair_verify(char const *file, int line, fr_pair_list_t const *list, fr_pair_t const *vp) CC_HINT(nonnull(4));
155 
156 void fr_pair_list_verify(char const *file, int line,
157  TALLOC_CTX const *expected, fr_pair_list_t const *list) CC_HINT(nonnull(4));
158 
159 # define PAIR_VERIFY(_x) fr_pair_verify(__FILE__, __LINE__, NULL, _x)
160 # define PAIR_VERIFY_WITH_LIST(_l, _x) fr_pair_verify(__FILE__, __LINE__, _l, _x)
161 # define PAIR_LIST_VERIFY(_x) fr_pair_list_verify(__FILE__, __LINE__, NULL, _x)
162 #else
163 DIAG_OFF(nonnull-compare)
164 /** Wrapper function to defeat nonnull checks
165  *
166  * We may sprinkle PAIR_VERIFY and PAIR_LIST_VERIFY in functions which
167  * have their pair argument marked up as nonnull.
168  *
169  * This would usually generate errors when WITH_VERIFY_PTR is not
170  * defined, as the assert macros check for an arguments NULLness.
171  *
172  * This function wraps the assert but has nonnull-compare disabled
173  * meaning a warning won't be emitted.
174  */
175 static inline bool fr_pair_nonnull_assert(fr_pair_t const *vp)
176 {
177  return fr_cond_assert(vp);
178 }
179 
181 {
182  return fr_cond_assert(pair_list);
183 }
184 DIAG_ON(nonnull-compare)
185 
186 /*
187  * Even if were building without WITH_VERIFY_PTR
188  * the pointer must not be NULL when these various macros are used
189  * so we can add some sneaky soft asserts.
190  */
191 # define PAIR_VERIFY(_x) fr_pair_nonnull_assert(_x)
192 # define PAIR_VERIFY_WITH_LIST(_l, _x) fr_pair_list_nonnull_assert(_l); \
193  fr_pair_nonnull_assert(_x)
194 # define PAIR_LIST_VERIFY(_x) fr_pair_list_nonnull_assert(_x)
195 #endif
196 
197 
198 #ifdef TEST_CHECK
199 /** Macro for use in acutest tests
200  */
201 #define TEST_CHECK_PAIR(_got, _exp) \
202 do { \
203  fr_pair_t const *_our_got = (_got); \
204  fr_pair_t const *_our_exp = (_exp); \
205  TEST_CHECK_(_our_exp == _our_got, "%s", #_got); \
206  if (_our_exp) { \
207  TEST_MSG("Expected pair : %s - %p (%s)", (_our_exp)->da->name, _our_exp, talloc_get_name(_our_exp)); \
208  } else { \
209  TEST_MSG("Expected pair : NULL"); \
210  } \
211  if (_our_got) { \
212  TEST_MSG("Got pair : %s - %p (%s)", (_our_got)->da->name, _our_got, talloc_get_name(_our_got)); \
213  } else { \
214  TEST_MSG("Got Pair : NULL"); \
215  } \
216 } while(0)
217 
218 #define TEST_CHECK_PAIR_NEQ(_got, _neq) \
219 do { \
220  fr_pair_t const *_our_got = (_got); \
221  fr_pair_t const *_our_neq = (_neq); \
222  TEST_CHECK_(_our_got != _our_neq, "%s", #_got); \
223  if (_our_neq) { \
224  TEST_MSG("Pair must not equal : %s - %p (%s)", (_our_neq)->da->name, _our_neq, talloc_get_name(_our_neq)); \
225  } else { \
226  TEST_MSG("Pair must not equal : NULL"); \
227  } \
228 } while(0)
229 #endif
230 
231 /*
232  * Helper macros for adding pairs to lists and assigning a value to them
233  */
234 
235 /** Check a pair's data type matches the DA data type
236  *
237  * @param[in] vp to check consistency of.
238  * @return
239  * - true for match
240  * - false for error
241  */
242 static inline bool vp_da_data_type_check(fr_pair_t *vp)
243 {
244  if (vp->vp_type == vp->da->type) return true;
245 
246  fr_strerror_printf("fr_pair_t attribute %p \"%s\" data type (%s) does not match da type (%s)",
247  vp->da, vp->da->name,
248  fr_table_str_by_value(fr_type_table, vp->vp_type, "invalid"),
249  fr_table_str_by_value(fr_type_table, vp->da->type, "invalid"));
250  return false;
251 }
252 
253 /** Iterate over the contents of a #fr_pair_list_t
254  *
255  * The iteration variable can be safely removed from the list at each pass.
256  *
257  * @param[in] _list_head to iterate over.
258  * @param[in] _iter Name of iteration variable.
259  * Will be declared in the scope of the loop.
260  */
261 #define fr_pair_list_foreach(_list_head, _iter) \
262  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))
263 
264 /** Iterate over the leaf nodes of a #fr_pair_list_t
265  *
266  * The iteration variable CANNOT be modified. This is a read-only operation.
267  *
268  * @param[in] _list_head to iterate over.
269  * @param[in] _iter Name of iteration variable.
270  * Will be declared in the scope of the loop.
271  */
272 #define fr_pair_list_foreach_leaf(_list_head, _iter) \
273  for (fr_pair_t *_iter = fr_pair_list_iter_leaf(_list_head, NULL); _iter != NULL; _iter = fr_pair_list_iter_leaf(_list_head, _iter))
274 
275 /** Append a pair to a list, assigning its value.
276  *
277  * Version for simple C data types
278  *
279  * @param[in] _ctx to allocate the pair in
280  * @param[out] _vp the allocated pair
281  * @param[in] _list to append the pair to
282  * @param[in] _attr to use when creating pair
283  * @param[in] _val to assign to the pair
284  * @param[in] _tainted does the value come from a trusted source
285  */
286 #define fr_pair_list_append_by_da(_ctx, _vp, _list, _attr, _val, _tainted) \
287 do { \
288  _vp = NULL; \
289  if (fr_pair_append_by_da(_ctx, &_vp, _list, _attr) < 0) break; \
290  fr_value_box(&_vp->data, _val, _tainted); \
291  if (!vp_da_data_type_check(_vp)) { \
292  fr_pair_delete(_list, _vp); \
293  _vp = NULL; \
294  } \
295 } while (0)
296 
297 /** Append a pair to a list, assigning its value.
298  *
299  * Version for char* and uint8_t*
300  *
301  * @param[in] _ctx to allocate the pair in
302  * @param[out] _vp the allocated pair
303  * @param[in] _list to append the pair to
304  * @param[in] _attr to use when creating pair
305  * @param[in] _val to assign to the pair
306  * @param[in] _len of value
307  * @param[in] _tainted does the value come from a trusted source
308  */
309 #define fr_pair_list_append_by_da_len(_ctx, _vp, _list, _attr, _val, _len, _tainted) \
310 do { \
311  _vp = NULL; \
312  if (fr_pair_append_by_da(_ctx, &_vp, _list, _attr) < 0) break; \
313  fr_value_box_len(_vp, &_vp->data, _val, _len, _tainted); \
314  if (!vp_da_data_type_check(_vp)) { \
315  fr_pair_delete(_list, _vp); \
316  _vp = NULL; \
317  } \
318 } while (0)
319 
320 #define fr_pair_list_append_by_da_parent(_ctx, _vp, _list, _attr, _val, _tainted) \
321 do { \
322  _vp = NULL; \
323  if (fr_pair_append_by_da_parent(_ctx, &_vp, _list, _attr) < 0) break; \
324  fr_value_box(&_vp->data, _val, _tainted); \
325  if (!vp_da_data_type_check(_vp)) { \
326  fr_pair_delete(_list, _vp); \
327  _vp = NULL; \
328  } \
329 } while (0)
330 
331 #define fr_pair_list_append_by_da_parent_len(_ctx, _vp, _list, _attr, _val, _len, _tainted) \
332 do { \
333  _vp = NULL; \
334  if (fr_pair_append_by_da_parent(_ctx, &vp, _list, _attr) < 0) break; \
335  fr_value_box_len(_vp, &_vp->data, _val, _len, _tainted); \
336  if (!vp_da_data_type_check(_vp)) { \
337  fr_pair_delete(_list, _vp); \
338  _vp = NULL; \
339  } \
340 } while (0)
341 
342 /** Prepend a pair to a list, assigning its value
343  *
344  * Version for simple C data types
345  *
346  * @param[in] _ctx to allocate the pair in
347  * @param[out] _vp the allocated pair
348  * @param[in] _list to prepend the pair to
349  * @param[in] _attr to use when creating pair
350  * @param[in] _val to assign to the pair
351  * @param[in] _tainted does the value come from a trusted source
352  */
353 #define fr_pair_list_prepend_by_da(_ctx, _vp, _list, _attr, _val, _tainted) \
354 do { \
355  _vp = NULL; \
356  if (fr_pair_prepend_by_da(_ctx, &_vp, _list, _attr) < 0) break; \
357  fr_value_box(&_vp->data, _val, _tainted); \
358  if (!vp_da_data_type_check(_vp)) { \
359  fr_pair_delete(_list, _vp); \
360  _vp = NULL; \
361  } \
362 } while (0)
363 
364 /** Prepend a pair to a list, assigning its value.
365  *
366  * Version for char* and uint8_t*
367  *
368  * @param[in] _ctx to allocate the pair in
369  * @param[out] _vp the allocated pair
370  * @param[in] _list to prepend the pair to
371  * @param[in] _attr to use when creating pair
372  * @param[in] _val to assign to the pair
373  * @param[in] _len of value
374  * @param[in] _tainted does the value come from a trusted source
375  */
376 #define fr_pair_list_prepend_by_da_len(_ctx, _vp, _list, _attr, _val, _len, _tainted) \
377 do { \
378  _vp = NULL; \
379  if (fr_pair_prepend_by_da(_ctx, &_vp, _list, _attr) < 0) break; \
380  fr_value_box_len(_vp, &_vp->data, _val, _len, _tainted); \
381  if (!vp_da_data_type_check(_vp)) { \
382  fr_pair_delete(_list, _vp); \
383  _vp = NULL; \
384  } \
385 } while (0)
386 
387 /** Replace a pair in a list, assigning its value
388  *
389  * Version for simple C data types.
390  * If the pair does not already exist, a new one is allocated.
391  *
392  * @param[in] _ctx to allocate the pair in
393  * @param[out] _vp the allocated pair
394  * @param[in] _list to append the pair to
395  * @param[in] _attr to use when creating pair
396  * @param[in] _val to assign to the pair
397  * @param[in] _tainted does the value come from a trusted source
398  */
399 #define fr_pair_list_replace_by_da(_ctx, _vp, _list, _attr, _val, _tainted) \
400 do { \
401  fr_pair_update_by_da(_ctx, _vp, _list, _attr, 0); \
402  if (!vp) break; \
403  fr_value_box(&_vp->data, _val, _tainted); \
404  if (!vp_da_data_type_check(_vp)) { \
405  fr_pair_delete(_list, _vp); \
406  _vp = NULL; \
407  } \
408 } while (0)
409 
410 /** Replace a pair in a list, assigning its value
411  *
412  * Version for char* and uint8_t*
413  * If the pair does not already exist, a new one is allocated.
414  *
415  * @param[in] _ctx to allocate the pair in
416  * @param[out] _vp the allocated pair
417  * @param[in] _list to append the pair to
418  * @param[in] _attr to use when creating pair
419  * @param[in] _val to assign to the pair
420  * @param[in] _len of value
421  * @param[in] _tainted does the value come from a trusted source
422  */
423 #define fr_pair_list_replace_by_da_len(_ctx, _vp, _list, _attr, _val, _len, _tainted) \
424 do { \
425  fr_pair_t *oldvp = fr_pair_find_by_da(_list, NULL, _attr); \
426  fr_pair_list_append_by_da_len(_ctx, _vp_, _list, _attr, _val, _len, _tainted) \
427  if (!vp_da_data_type_check(_vp)) { \
428  fr_pair_delete(_list, _vp); \
429  _vp = NULL; \
430  } \
431  if (!_vp) break; \
432  if (oldvp) fr_pair_delete(_list, oldvp); \
433 } while (0)
434 
435 /* Initialisation */
436 /** @hidecallergraph */
438 
439 void fr_pair_init_null(fr_pair_t *vp) CC_HINT(nonnull);
440 
441 /* Allocation and management */
442 fr_pair_t *fr_pair_alloc_null(TALLOC_CTX *ctx) CC_HINT(warn_unused_result);
443 
444 fr_pair_list_t *fr_pair_list_alloc(TALLOC_CTX *ctx) CC_HINT(warn_unused_result);
445 
446 fr_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));
447 
448 /** @hidecallergraph */
449 fr_pair_t *fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da) CC_HINT(warn_unused_result) CC_HINT(nonnull(2));
450 
452  CC_HINT(nonnull(2, 3));
453 
454 fr_pair_t *fr_pair_afrom_child_num(TALLOC_CTX *ctx, fr_dict_attr_t const *parent, unsigned int attr) CC_HINT(warn_unused_result);
455 
456 fr_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));
457 
458 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) CC_HINT(warn_unused_result) CC_HINT(nonnull(2,3));
459 
460 fr_pair_t *fr_pair_copy(TALLOC_CTX *ctx, fr_pair_t const *vp) CC_HINT(nonnull(2)) CC_HINT(warn_unused_result);
461 
462 int fr_pair_steal(TALLOC_CTX *ctx, fr_pair_t *vp) CC_HINT(nonnull);
463 
464 int fr_pair_steal_append(TALLOC_CTX *nctx, fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull);
465 
466 int fr_pair_steal_prepend(TALLOC_CTX *nctx, fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull);
467 
468 /* Searching and list modification */
469 int fr_pair_raw_afrom_pair(fr_pair_t *vp, uint8_t const *data, size_t data_len) CC_HINT(nonnull);
470 
471 bool fr_pair_matches_da(void const *item, void const *uctx) CC_HINT(nonnull);
472 
473 /** @hidecallergraph */
474 unsigned int fr_pair_count_by_da(fr_pair_list_t const *list, fr_dict_attr_t const *da)
475  CC_HINT(nonnull);
476 
477 /** @hidecallergraph */
479  fr_pair_t const *prev, fr_dict_attr_t const *da) CC_HINT(nonnull(1,3));
480 
482  fr_dict_attr_t const *da, unsigned int idx) CC_HINT(nonnull);
483 
485  fr_dict_attr_t const *da) CC_HINT(nonnull(1,3));
486 
488  fr_pair_t const *prev, fr_dict_attr_t const *da) CC_HINT(nonnull(1,3));
489 
491  fr_dict_attr_t const *parent, unsigned int attr) CC_HINT(nonnull(1,3));
492 
494  fr_dict_attr_t const *parent, unsigned int attr,
495  unsigned int idx) CC_HINT(nonnull);
496 
497 /** @hidecallergraph */
498 int fr_pair_append(fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull);
499 
500 int fr_pair_prepend(fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull);
501 
502 int fr_pair_insert_after(fr_pair_list_t *list, fr_pair_t *pos, fr_pair_t *to_add) CC_HINT(nonnull(1,3));
503 
504 int fr_pair_insert_before(fr_pair_list_t *list, fr_pair_t *pos, fr_pair_t *to_add) CC_HINT(nonnull(1,3));
505 
506 void fr_pair_replace(fr_pair_list_t *list, fr_pair_t *to_replace, fr_pair_t *vp) CC_HINT(nonnull);
507 
509  fr_dict_attr_t const *parent, unsigned int attr) CC_HINT(nonnull);
510 
511 int fr_pair_append_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list,
512  fr_dict_attr_t const *da) CC_HINT(nonnull(3,4));
513 
514 int fr_pair_prepend_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list,
515  fr_dict_attr_t const *da) CC_HINT(nonnull(3,4));
516 
517 int fr_pair_append_by_da_parent(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list,
518  fr_dict_attr_t const *da) CC_HINT(nonnull(3,4));
519 
521  fr_dict_attr_t const *da) CC_HINT(nonnull(1,3));
522 
523 static 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,
524  fr_dict_attr_t const *da)
525 {
526  fr_pair_t *vp;
527 
528  vp = fr_pair_find_by_da(list, NULL, da);
529  if (vp) {
530  *out = vp;
531  return 0;
532  }
533 
534  return fr_pair_append_by_da(ctx, out, list, da);
535 }
536 
537 
539 
541 
542 int fr_pair_delete(fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull);
543 
544 /* functions for FR_TYPE_STRUCTURAL */
546 
548 
550 
552 
554 
555 /** Initialises a special dcursor with callbacks that will maintain the attr sublists correctly
556  *
557  * Filters can be applied later with fr_dcursor_filter_set.
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  * Filters can be applied later with fr_dcursor_filter_set.
582  *
583  * @note This is the only way to use a dcursor in non-const mode with fr_pair_list_t.
584  *
585  * @param[out] _cursor to initialise.
586  * @param[in] _list to iterate over.
587  * @return
588  * - NULL if src does not point to any items.
589  * - The first pair in the list.
590  */
591 #define fr_pair_dcursor_init(_cursor, _list) \
592  _fr_pair_dcursor_init(_cursor, \
593  _list, \
594  IS_CONST(fr_pair_list_t *, _list))
596  bool is_const) CC_HINT(nonnull);
597 
598 /** Initializes a child dcursor from a parent cursor, with an iteration function.
599  *
600  * Filters can be applied later with fr_dcursor_filter_set.
601  *
602  * @note This is the only way to use a dcursor in non-const mode with fr_pair_list_t.
603  *
604  * @param[out] cursor to initialise.
605  * @param[in] list to iterate over.
606  * @param[in] parent parent cursor to take the iterator from
607  * @return
608  * - NULL if src does not point to any items.
609  * - The first pair in the list.
610  */
612 {
613  fr_pair_t *vp = fr_pair_dcursor_init(cursor, list);
614 
615  fr_dcursor_copy_iter(cursor, parent);
616  return vp;
617 }
618 
619 /** Initialise a cursor that will return only attributes matching the specified #fr_dict_attr_t
620  *
621  * @param[in] _cursor to initialise.
622  * @param[in] _list to iterate over.
623  * @param[in] _da to search for.
624  * @return
625  * - The first matching pair.
626  * - NULL if no pairs match.
627  */
628 #define fr_pair_dcursor_by_da_init(_cursor, _list, _da) \
629  _fr_pair_dcursor_by_da_init(_cursor, \
630  _list, \
631  _da, \
632  IS_CONST(fr_pair_list_t *, _list))
634  fr_pair_list_t const *list, fr_dict_attr_t const *da,
635  bool is_const) CC_HINT(nonnull);
636 
637 /** Initialise a cursor that will return only attributes descended from the specified #fr_dict_attr_t
638  *
639  * @param[in] _cursor to initialise.
640  * @param[in] _list to iterate over.
641  * @param[in] _da who's decentness to search for.
642  * @return
643  * - The first matching pair.
644  * - NULL if no pairs match.
645  */
646 #define fr_pair_dcursor_by_ancestor_init(_cursor, _list, _da) \
647  _fr_pair_dcursor_by_ancestor_init(_cursor, \
648  _list, \
649  _da, \
650  IS_CONST(fr_pair_list_t *, _list))
652  fr_pair_list_t const *list, fr_dict_attr_t const *da,
653  bool is_const) CC_HINT(nonnull);
654 
656 
658 
659 /** Compare two attributes using and operator.
660  *
661  * @return
662  * - 1 if equal.
663  * - 0 if not equal.
664  * - -1 on failure.
665  */
666 #define fr_pair_cmp_op(_op, _a, _b) fr_value_box_cmp_op(_op, &_a->data, &_b->data)
667 
668 int8_t fr_pair_cmp_by_da(void const *a, void const *b);
669 
670 int8_t fr_pair_cmp_by_parent_num(void const *a, void const *b);
671 
672 int fr_pair_cmp(fr_pair_t const *a, fr_pair_t const *b);
673 
674 int fr_pair_list_cmp(fr_pair_list_t const *a, fr_pair_list_t const *b) CC_HINT(nonnull);
675 
676 /* Filtering */
677 void fr_pair_validate_debug(fr_pair_t const *failed[2]) CC_HINT(nonnull);
678 
679 bool fr_pair_validate(fr_pair_t const *failed[2], fr_pair_list_t *filter,
680  fr_pair_list_t *list) CC_HINT(nonnull(2,3));
681 
682 bool fr_pair_validate_relaxed(fr_pair_t const *failed[2], fr_pair_list_t *filter,
683  fr_pair_list_t *list) CC_HINT(nonnull(2,3));
684 
685 bool fr_pair_immutable(fr_pair_t const *vp) CC_HINT(nonnull);
686 
687 static inline CC_HINT(nonnull, always_inline)
689 {
690  vp->vp_immutable = true;
691 }
692 
693 static inline CC_HINT(nonnull, always_inline)
695 {
696  vp->vp_immutable = false;
697 }
698 
699 
700 /* Lists */
701 int fr_pair_list_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from);
702 
703 void fr_pair_list_steal(TALLOC_CTX *ctx, fr_pair_list_t *list);
704 
706 
707 int fr_pair_list_copy_by_da(TALLOC_CTX *ctx, fr_pair_list_t *to,
708  fr_pair_list_t const *from, fr_dict_attr_t const *da, unsigned int count);
709 
710 int fr_pair_list_copy_by_ancestor(TALLOC_CTX *ctx, fr_pair_list_t *to,
711  fr_pair_list_t const *from,
712  fr_dict_attr_t const *parent_da) CC_HINT(nonnull);
713 
714 int fr_pair_sublist_copy(TALLOC_CTX *ctx, fr_pair_list_t *to,
715  fr_pair_list_t const *from,
716  fr_pair_t const *start, unsigned int count) CC_HINT(nonnull(2,3));
717 
718 #ifndef _PAIR_INLINE
719 /** @hidecallergraph */
720 void fr_pair_list_free(fr_pair_list_t *list) CC_HINT(nonnull);
721 
723 
724 
725 /** @hidecallergraph */
726 bool fr_pair_list_empty(fr_pair_list_t const *list) CC_HINT(nonnull);
727 
728 size_t fr_pair_list_num_elements(fr_pair_list_t const *list) CC_HINT(nonnull);
729 
731 
733 
734 void fr_pair_list_sort(fr_pair_list_t *list, fr_cmp_t cmp) CC_HINT(nonnull);
735 
736 void fr_pair_list_append(fr_pair_list_t *dst, fr_pair_list_t *src) CC_HINT(nonnull);
737 
739 
740 /** @hidecallergraph */
741 fr_pair_t *fr_pair_list_head(fr_pair_list_t const *list) CC_HINT(nonnull);
742 
743 /** @hidecallergraph */
744 fr_pair_t *fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item) CC_HINT(nonnull(1));
745 
746 fr_pair_t *fr_pair_list_prev(fr_pair_list_t const *list, fr_pair_t const *item) CC_HINT(nonnull(1));
747 
748 fr_pair_t *fr_pair_list_tail(fr_pair_list_t const *list) CC_HINT(nonnull);
749 #endif
750 
751 /** @name Pair to pair copying
752  *
753  * @{
754  */
755 void fr_pair_value_clear(fr_pair_t *vp) CC_HINT(nonnull);
756 
757 int fr_pair_value_copy(fr_pair_t *dst, fr_pair_t *src) CC_HINT(nonnull);
758 /** @} */
759 
760 /** @name Assign and manipulate binary-unsafe C strings
761  *
762  * @{
763  */
765  char const *value, size_t len, fr_sbuff_unescape_rules_t const *erules,
766  bool tainted) CC_HINT(nonnull(1,2));
767 
768 int fr_pair_value_strdup(fr_pair_t *vp, char const *src, bool tainted) CC_HINT(nonnull);
769 
770 int fr_pair_value_strdup_shallow(fr_pair_t *vp, char const *src, bool tainted) CC_HINT(nonnull);
771 
773 
775  char const *fmt, ...) CC_HINT(nonnull) CC_HINT(format (printf, 2, 3));
776 /** @} */
777 
778 /** @name Assign and manipulate binary-safe strings
779  *
780  * @{
781  */
782 int fr_pair_value_bstr_alloc(fr_pair_t *vp, char **out, size_t size, bool tainted) CC_HINT(nonnull(1));
783 
784 int fr_pair_value_bstr_realloc(fr_pair_t *vp, char **out, size_t size) CC_HINT(nonnull(1));
785 
786 int fr_pair_value_bstrndup(fr_pair_t *vp, char const *src, size_t len, bool tainted) CC_HINT(nonnull(1));
787 
788 int fr_pair_value_bstrdup_buffer(fr_pair_t *vp, char const *src, bool tainted) CC_HINT(nonnull);
789 
790 int fr_pair_value_bstrndup_shallow(fr_pair_t *vp, char const *src, size_t len, bool tainted) CC_HINT(nonnull(1));
791 
792 int fr_pair_value_bstrdup_buffer_shallow(fr_pair_t *vp, char const *src, bool tainted) CC_HINT(nonnull);
793 
794 int fr_pair_value_bstrn_append(fr_pair_t *vp, char const *src, size_t len, bool tainted) CC_HINT(nonnull(1));
795 
796 int fr_pair_value_bstr_append_buffer(fr_pair_t *vp, char const *src, bool tainted) CC_HINT(nonnull);
797  /** @} */
798 
799 /** @name Assign and manipulate octets strings
800  *
801  * @{
802  */
803 int fr_pair_value_mem_alloc(fr_pair_t *vp, uint8_t **out, size_t size, bool tainted) CC_HINT(nonnull(1));
804 
805 int fr_pair_value_mem_realloc(fr_pair_t *vp, uint8_t **out, size_t size) CC_HINT(nonnull(1));
806 
807 int fr_pair_value_memdup(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted) CC_HINT(nonnull(1));
808 
809 int fr_pair_value_memdup_buffer(fr_pair_t *vp, uint8_t const *src, bool tainted) CC_HINT(nonnull);
810 
811 int fr_pair_value_memdup_shallow(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted) CC_HINT(nonnull(1));
812 
813 int fr_pair_value_memdup_buffer_shallow(fr_pair_t *vp, uint8_t const *src, bool tainted) CC_HINT(nonnull);
814 
815 int fr_pair_value_mem_append(fr_pair_t *vp, uint8_t *src, size_t len, bool tainted) CC_HINT(nonnull(1));
816 
817 int fr_pair_value_mem_append_buffer(fr_pair_t *vp, uint8_t *src, bool tainted) CC_HINT(nonnull);
818  /** @} */
819 
820 /** @name Enum functions
821  *
822  * @{
823  */
824 char const *fr_pair_value_enum(fr_pair_t const *vp, char buff[static 20]) CC_HINT(nonnull);
825 
827 /** @} */
828 
829 /** @name Printing functions
830  *
831  * @{
832  */
834  fr_pair_t const *vp, fr_token_t quote) CC_HINT(nonnull);
835 
836 static inline fr_slen_t CC_HINT(nonnull(2,3))
837  fr_pair_aprint_value_quoted(TALLOC_CTX *ctx, char **out,
838  fr_pair_t const *vp, fr_token_t quote)
840 
842  fr_pair_t const *vp) CC_HINT(nonnull(1,3));
843 
845  fr_pair_t const *vp) CC_HINT(nonnull(1,3));
846 
848 
849 static inline fr_slen_t CC_HINT(nonnull(2,4))
850  fr_pair_aprint(TALLOC_CTX *ctx, char **out, fr_dict_attr_t const *parent, fr_pair_t const *vp)
852 
853 static inline fr_slen_t CC_HINT(nonnull(2,4))
854  fr_pair_aprint_secure(TALLOC_CTX *ctx, char **out, fr_dict_attr_t const *parent, fr_pair_t const *vp)
856 
857 #define fr_pair_list_log(_log, _lvl, _list) _fr_pair_list_log(_log, _lvl, NULL, _list, __FILE__, __LINE__)
858 void _fr_pair_list_log(fr_log_t const *log, int lvl, fr_pair_t *parent,
859  fr_pair_list_t const *list, char const *file, int line) CC_HINT(nonnull(1,4));
860 
861 void fr_pair_list_debug(fr_pair_list_t const *list) CC_HINT(nonnull);
862 void fr_pair_debug(fr_pair_t const *pair) CC_HINT(nonnull);
863 
864 /** @} */
865 
866 void fr_pair_list_tainted(fr_pair_list_t *vps) CC_HINT(nonnull);
867 
868 void fr_pair_list_afrom_box(TALLOC_CTX *ctx, fr_pair_list_t *out,
869  fr_dict_t const *dict, fr_value_box_t *box) CC_HINT(nonnull);
870 
871 /* Tokenization */
872 typedef struct {
873  TALLOC_CTX *ctx; //!< to allocate VPs in
874  fr_dict_attr_t const *parent; //!< current attribute to allocate VPs in
875  fr_pair_list_t *list; //!< of VPs to add
876 } fr_pair_ctx_t;
877 
878 ssize_t fr_pair_ctx_afrom_str(fr_pair_ctx_t *pair_ctx, char const *in, size_t inlen) CC_HINT(nonnull);
879 void fr_pair_ctx_reset(fr_pair_ctx_t *pair_ctx, fr_dict_t const *dict) CC_HINT(nonnull);
880 
881 void fr_fprintf_pair(FILE *fp, char const *msg, fr_pair_t const *vp);
882 void fr_fprintf_pair_list(FILE *fp, fr_pair_list_t const *list);
883 
884 #undef _CONST
885 #ifdef __cplusplus
886 }
887 #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
static fr_dict_t * dict
Definition: fuzzer.c:46
#define DIAG_ON(_x)
Definition: build.h:456
#define RCSIDH(h, id)
Definition: build.h:482
#define DIAG_OFF(_x)
Definition: build.h:455
fr_dcursor_eval_t void const * uctx
Definition: dcursor.h:546
void *(* fr_dcursor_iter_t)(fr_dlist_head_t *list, void *to_eval, void *uctx)
Callback for implementing custom iterators.
Definition: dcursor.h:51
fr_dcursor_iter_t iter
Definition: dcursor.h:147
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
return item
Definition: dcursor.h:553
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
Definition: debug.h:139
static fr_slen_t in
Definition: dict.h:821
Test enumeration values.
Definition: dict_test.h:92
Head of a doubly linked list.
Definition: dlist.h:51
long int ssize_t
Definition: merged_model.c:24
unsigned char uint8_t
Definition: merged_model.c:30
ssize_t fr_slen_t
Definition: merged_model.c:35
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.
Definition: merged_model.c:163
static char buff[sizeof("18446744073709551615")+3]
Definition: size_tests.c:41
return count
Definition: module.c:163
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:406
bool fr_pair_matches_da(void const *item, void const *uctx)
Evaluation function for matching if vp matches a given da.
Definition: pair.c:3476
fr_pair_t * fr_pair_list_head(fr_pair_list_t const *list)
Get the head of a valuepair list.
Definition: pair_inline.c:43
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:2406
fr_pair_t * fr_pair_copy(TALLOC_CTX *ctx, fr_pair_t const *vp))
Copy a single valuepair.
Definition: pair.c:489
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:2730
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:2047
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:3011
fr_dlist_head_t * fr_pair_list_to_dlist(fr_pair_list_t const *list)
Get the dlist head from a pair list.
Definition: pair_inline.c:162
TALLOC_CTX * ctx
to allocate VPs in
Definition: pair.h:873
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:2930
struct pair_list_s fr_pair_list_t
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:670
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:893
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))
Convert string value to native attribute value.
Definition: pair.c:2589
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:2508
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:3158
int fr_pair_value_aprintf(fr_pair_t *vp, char const *fmt,...)
Print data into an "string" data type.
Definition: pair.c:2698
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:1713
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:1373
void fr_fprintf_pair_list(FILE *fp, fr_pair_list_t const *list)
Definition: pair.c:3610
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:2981
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:2205
fr_pair_t * fr_pair_list_tail(fr_pair_list_t const *list)
Get the tail of a valuepair list.
Definition: pair_inline.c:56
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:167
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:94
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:242
fr_pair_t * fr_pair_parent(fr_pair_t const *vp)
Return a pointer to the parent pair.
Definition: pair.c:942
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:283
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:867
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
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:611
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:2955
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:1406
int fr_pair_value_mem_append_buffer(fr_pair_t *vp, uint8_t *src, bool tainted)
Append a talloced buffer to an existing "octets" type value pair.
Definition: pair.c:3101
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.
Definition: pair_inline.c:125
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:717
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:1466
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:70
void fr_pair_validate_debug(fr_pair_t const *failed[2])
Write an error to the library errorbuff detailing the mismatch.
Definition: pair.c:2093
int fr_pair_value_strdup(fr_pair_t *vp, char const *src, bool tainted)
Copy data into an "string" data type.
Definition: pair.c:2634
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:546
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:2855
void fr_pair_init_null(fr_pair_t *vp)
Initialise fields in an fr_pair_t without assigning a da.
Definition: pair.c:147
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:1143
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:1921
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:1689
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.
Definition: pair_inline.c:140
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:1969
void fr_pair_list_debug(fr_pair_list_t const *list)
Dumps a list to the default logging destination - Useful for calling from debuggers.
Definition: pair_print.c:318
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:770
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:1439
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:1314
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:3036
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:2810
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:2455
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:175
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:104
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:2784
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:523
void fr_pair_list_free(fr_pair_list_t *list)
Free memory used by a valuepair list.
Definition: pair_inline.c:113
static void fr_pair_clear_immutable(fr_pair_t *vp)
Definition: pair.h:694
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.
Definition: pair_inline.c:182
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:467
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:1345
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:371
#define _CONST
Definition: pair.h:43
void fr_fprintf_pair(FILE *fp, char const *msg, fr_pair_t const *vp)
Definition: pair.c:3618
int fr_pair_value_bstr_append_buffer(fr_pair_t *vp, char const *src, bool tainted)
Append a talloced buffer to an existing "string" type value pair.
Definition: pair.c:2903
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:2835
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:1162
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.
Definition: pair_inline.c:195
bool fr_pair_immutable(fr_pair_t const *vp)
Definition: pair.c:2280
void fr_pair_list_tainted(fr_pair_list_t *vps)
Mark up a list of VPs as tainted.
Definition: pair.c:3447
void fr_pair_value_clear(fr_pair_t *vp)
Free/zero out value (or children) of a given VP.
Definition: pair.c:2533
static void fr_pair_set_immutable(fr_pair_t *vp)
Definition: pair.h:688
fr_pair_list_t * list
of VPs to add
Definition: pair.h:875
void fr_pair_debug(fr_pair_t const *pair)
Dumps a pair to the default logging destination - Useful for calling from debuggers.
Definition: pair_print.c:327
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:1826
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:741
fr_pair_list_t * fr_pair_list_from_dlist(fr_dlist_head_t const *list)
Get the pair list head from a dlist.
Definition: pair_inline.c:172
static fr_slen_t vp
Definition: pair.h:839
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:1808
int fr_pair_value_copy(fr_pair_t *dst, fr_pair_t *src)
Copy the value from one pair to another.
Definition: pair.c:2563
static bool fr_pair_list_nonnull_assert(fr_pair_list_t const *pair_list)
Definition: pair.h:180
fr_pair_list_t * fr_pair_list_alloc(TALLOC_CTX *ctx)
Allocate a new pair list on the heap.
Definition: pair.c:117
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:40
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:83
int fr_pair_steal(TALLOC_CTX *ctx, fr_pair_t *vp)
Steal one VP.
Definition: pair.c:521
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:2128
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_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:1103
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:1523
fr_pair_list_t * fr_pair_parent_list(fr_pair_t const *vp)
Return a pointer to the parent pair list.
Definition: pair.c:927
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:2677
#define fr_pair_dcursor_init(_cursor, _list)
Initialises a special dcursor with callbacks that will maintain the attr sublists correctly.
Definition: pair.h:591
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:305
fr_dict_attr_t const * parent
current attribute to allocate VPs in
Definition: pair.h:874
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:1596
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:314
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:2755
int fr_pair_value_mem_append(fr_pair_t *vp, uint8_t *src, size_t len, bool tainted))
Append bytes from a buffer to an existing "octets" type value pair.
Definition: pair.c:3078
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:693
int fr_pair_value_bstrn_append(fr_pair_t *vp, char const *src, size_t len, bool tainted))
Append bytes from a buffer to an existing "string" type value pair.
Definition: pair.c:2880
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:3572
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:1298
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_list_parent(fr_pair_list_t const *list)
Return a pointer to the parent pair which contains this list.
Definition: pair.c:956
size_t fr_pair_list_num_elements(fr_pair_list_t const *list)
Get the length of a list of fr_pair_t.
Definition: pair_inline.c:151
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:569
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:1493
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:1038
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:593
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:1248
fr_pair_list_t * fr_pair_children(fr_pair_t *head)
Get the child list of a group.
Definition: pair.c:917
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:166
int8_t fr_pair_cmp_by_da(void const *a, void const *b)
Order attributes by their da, and tag.
Definition: pair.c:1844
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:3056
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:2658
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:233
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:1125
static fr_slen_t parent
Definition: pair.h:851
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:243
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:408
char const * fr_pair_value_enum(fr_pair_t const *vp, char buff[static 20])
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
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:1265
static size_t char fr_sbuff_t size_t inlen
Definition: value.h:997
int nonnull(2, 5))
int format(printf, 5, 0))
static size_t char ** out
Definition: value.h:997