24RCSIDH(value_h,
"$Id: 61cda4df140336ecd5d90f6e7492f6ef98fc819d $")
30#define FR_MAX_STRING_LEN 254
38#include <freeradius-devel/build.h>
39#include <freeradius-devel/util/dcursor.h>
40#include <freeradius-devel/missing.h>
41#include <freeradius-devel/util/dbuff.h>
42#include <freeradius-devel/util/debug.h>
43#include <freeradius-devel/util/dict.h>
44#include <freeradius-devel/util/dlist.h>
45#include <freeradius-devel/util/inet.h>
46#include <freeradius-devel/util/log.h>
47#include <freeradius-devel/util/strerror.h>
48#include <freeradius-devel/util/table.h>
49#include <freeradius-devel/util/time.h>
50#include <freeradius-devel/util/token.h>
51#include <freeradius-devel/util/types.h>
61# error _CONST can only be defined in the local header
91# define FR_VALUE_BOX_MAGIC RADIUSD_MAGIC_NUMBER
107 char const *
_CONST strvalue;
172#define FR_VALUE_BOX_SAFE_FOR_NONE ((uintptr_t) 0)
173#define FR_VALUE_BOX_SAFE_FOR_ANY (~((uintptr_t) 0))
217#if defined(WITH_VERIFY_PTR) || !defined(NDEBUG)
247#define fr_value_box_list_foreach(_list_head, _iter) fr_dlist_foreach(fr_value_box_list_dlist_head(_list_head), fr_value_box_t, _iter)
264#define vb_should_free(_action) ((_action & FR_VALUE_BOX_LIST_FREE_BOX) == FR_VALUE_BOX_LIST_FREE_BOX)
265#define vb_should_free_value(_action) ((_action & FR_VALUE_BOX_LIST_FREE_BOX_VALUE) == FR_VALUE_BOX_LIST_FREE_BOX_VALUE)
266#define vb_should_remove(_action) ((_action & FR_VALUE_BOX_LIST_REMOVE) == FR_VALUE_BOX_LIST_REMOVE)
269#define VALUE_BOX_NDEBUG_INITIALISER .file = __FILE__, .line = __LINE__, .magic = FR_VALUE_BOX_MAGIC
271#define VALUE_BOX_NDEBUG_INITIALISER
281#define vb_strvalue datum.strvalue
282#define vb_octets datum.octets
283#define vb_void datum.ptr
284#define vb_group datum.children
285#define vb_attr datum.da
287#define vb_ip datum.ip
288#define vb_ipv4addr datum.ip.addr.v4.s_addr
289#define vb_ipv6addr datum.ip.addr.v6.s6_addr
291#define vb_ifid datum.ifid.addr
292#define vb_ether datum.ether.addr
294#define vb_bool datum.boolean
295#define vb_uint8 datum.uint8
296#define vb_uint16 datum.uint16
297#define vb_uint32 datum.uint32
298#define vb_uint64 datum.uint64
299#define vb_uint128 datum.uint128
301#define vb_int8 datum.int8
302#define vb_int16 datum.int16
303#define vb_int32 datum.int32
304#define vb_int64 datum.int64
306#define vb_float32 datum.float32
307#define vb_float64 datum.float64
309#define vb_date datum.date
311#define vb_size datum.size
312#define vb_timeval datum.timeval
313#define vb_time_delta datum.time_delta
315#define vb_length datum.length
316#define vb_safefor safety.safe_for
317#define vb_secret safety.secret
319#define vb_cursor datum.cursor
320#define vb_cursor_name datum.name
331#define _fr_box_with_len(_type, _field, _val, _len) &(fr_value_box_t){ .type = _type, _field = _val, .vb_length = _len, VALUE_BOX_NDEBUG_INITIALISER }
333#define fr_box_strvalue(_val) _fr_box_with_len(FR_TYPE_STRING, .vb_strvalue, _val, strlen(_val))
334#define fr_box_strvalue_len(_val, _len) _fr_box_with_len(FR_TYPE_STRING, .vb_strvalue, _val, _len)
336#define fr_box_octets(_val, _len) _fr_box_with_len(FR_TYPE_OCTETS, .vb_octets, _val, _len)
337#define fr_box_strvalue_buffer(_val) _fr_box_with_len(FR_TYPE_STRING, .vb_strvalue, _val, talloc_strlen(_val))
338#define fr_box_octets_buffer(_val) _fr_box_with_len(FR_TYPE_OCTETS, .vb_octets, _val, talloc_array_length(_val))
340#define _fr_box(_type, _field, _val) (&(fr_value_box_t){ .type = _type, _field = (_val), VALUE_BOX_NDEBUG_INITIALISER })
342#define fr_box_ipaddr(_val) _fr_box((((_val).af == AF_INET) ? \
343 (((_val).prefix == 32) ? FR_TYPE_IPV4_ADDR : \
344 FR_TYPE_IPV4_PREFIX) : \
345 (((_val).prefix == 128) ? FR_TYPE_IPV6_ADDR : \
346 FR_TYPE_IPV6_PREFIX)), \
348#define fr_box_ipv4addr(_val) _fr_box(FR_TYPE_IPV4_ADDR, .vb_ip, _val)
349#define fr_box_ipv4prefix(_val) _fr_box(FR_TYPE_IPV4_PREFIX, .vb_ip, _val)
350#define fr_box_ipv6addr(_val) _fr_box(FR_TYPE_IPV6_ADDR, .vb_ip, _val)
351#define fr_box_ipv6prefix(_val) _fr_box(FR_TYPE_IPV6_PREFIX, .vb_ip, _val)
353#define fr_box_ifid(_val) _fr_box(FR_TYPE_IFID, .vb_ifid, _val)
354#define fr_box_ether(_val) &(fr_value_box_t){ .type = FR_TYPE_ETHERNET, .vb_ether = { _val[0], _val[1], _val[2], _val[3], _val[4], _val[5] } }
356#define fr_box_bool(_val) _fr_box(FR_TYPE_BOOL, .vb_bool, _val)
358#define fr_box_uint8(_val) _fr_box(FR_TYPE_UINT8, .vb_uint8, _val)
359#define fr_box_uint16(_val) _fr_box(FR_TYPE_UINT16, .vb_uint16, _val)
360#define fr_box_uint32(_val) _fr_box(FR_TYPE_UINT32, .vb_uint32, _val)
361#define fr_box_uint64(_val) _fr_box(FR_TYPE_UINT64, .vb_uint64, _val)
362#define fr_box_uint128(_val) _fr_box(FR_TYPE_UINT128, .vb_uint128, _val)
364#define fr_box_int8(_val) _fr_box(FR_TYPE_INT8, .vb_int8, _val)
365#define fr_box_int16(_val) _fr_box(FR_TYPE_INT16, .vb_int16, _val)
366#define fr_box_int32(_val) _fr_box(FR_TYPE_INT32, .vb_int32, _val)
367#define fr_box_int64(_val) _fr_box(FR_TYPE_INT64, .vb_int64, _val)
369#define fr_box_float32(_val) _fr_box(FR_TYPE_FLOAT32, .vb_float32, _val)
370#define fr_box_float64(_val) _fr_box(FR_TYPE_FLOAT64, .vb_float64, _val)
372#define fr_box_date(_val) _fr_box(FR_TYPE_DATE, .vb_date, _val)
374#define fr_box_time(_val) _fr_box(FR_TYPE_DATE, .vb_date, fr_time_to_unix_time(_val))
376#define fr_box_size(_val) _fr_box(FR_TYPE_SIZE, .vb_size, _val)
378#define _fr_box_with_da(_type, _field, _val, _da) (&(fr_value_box_t){ .type = _type, _field = (_val), .enumv = (_da) })
380#define fr_box_time_delta_with_res(_val, _res) _fr_box_with_da(FR_TYPE_TIME_DELTA, \
383 (&(fr_dict_attr_t){ \
385 .type = FR_TYPE_TIME_DELTA, \
391#define fr_box_time_delta(_val) fr_box_time_delta_with_res((_val), FR_TIME_RES_SEC)
393#define fr_box_time_delta_sec(_val) fr_box_time_delta_with_res((_val), FR_TIME_RES_SEC)
395#define fr_box_time_delta_msec(_val) fr_box_time_delta_with_res((_val), FR_TIME_RES_MSEC)
397#define fr_box_time_delta_nsec(_val) fr_box_time_delta_with_res((_val), FR_TIME_RES_NSEC)
399#define fr_box_time_delta_usec(_val) fr_box_time_delta_with_res((_val), FR_TIME_RES_USEC)
408#define fr_box(_val) _Generic((_val), \
409 fr_ipaddr_t * : fr_box_ipaddr, \
410 fr_ipaddr_t const * : fr_box_ipaddr, \
411 fr_ethernet_t * : fr_box_ether, \
412 fr_ethernet_t const * : fr_box_ether, \
413 bool : fr_box_bool, \
414 int8_t : fr_box_int8, \
415 int16_t : fr_box_int16, \
416 int32_t : fr_box_int32, \
417 int64_t : fr_box_int16, \
418 uint8_t : fr_box_uint8, \
419 uint16_t : fr_box_uint16, \
420 uint32_t : fr_box_uint32, \
421 uint64_t : fr_box_uint64, \
422 size_t : fr_box_size, \
423 float : fr_box_float32, \
424 double : fr_box_float64 \
432#define fr_box_len( _val, _len) \
434 char * : fr_box_strvalue_len, \
435 char const * : fr_box_strvalue_len, \
436 uint8_t * : fr_box_octets, \
437 uint8_t const * : fr_box_octets \
449#define fr_box_is_null(_x) fr_type_is_null((_x)->type)
450#define fr_box_is_string(_x) fr_type_is_string((_x)->type)
451#define fr_box_is_octets(_x) fr_type_is_octets((_x)->type)
452#define fr_box_is_ipv4addr(_x) fr_type_is_ipv4addr((_x)->type)
453#define fr_box_is_ipv4prefix(_x) fr_type_is_ipv4prefix((_x)->type)
454#define fr_box_is_ipv6addr(_x) fr_type_is_ipv6addr((_x)->type)
455#define fr_box_is_ipv6prefix(_x) fr_type_is_ipv6prefix((_x)->type)
456#define fr_box_is_ifid(_x) fr_type_is_ifid((_x)->type)
457#define fr_box_is_combo_ipaddr(_x) fr_type_is_combo_ipaddr((_x)->type)
458#define fr_box_is_combo_ipprefix(_x) fr_type_is_combo_ipprefix((_x)->type)
459#define fr_box_is_ethernet(_x) fr_type_is_ethernet((_x)->type)
460#define fr_box_is_bool(_x) fr_type_is_bool((_x)->type)
461#define fr_box_is_uint8(_x) fr_type_is_uint8((_x)->type)
462#define fr_box_is_uint16(_x) fr_type_is_uint16((_x)->type)
463#define fr_box_is_uint32(_x) fr_type_is_uint32((_x)->type)
464#define fr_box_is_uint64(_x) fr_type_is_uint64((_x)->type)
465#define fr_box_is_int8(_x) fr_type_is_int8((_x)->type)
466#define fr_box_is_int16(_x) fr_type_is_int16((_x)->type)
467#define fr_box_is_int32(_x) fr_type_is_int32((_x)->type)
468#define fr_box_is_int64(_x) fr_type_is_int64((_x)->type)
469#define fr_box_is_float32(_x) fr_type_is_float32((_x)->type)
470#define fr_box_is_float64(_x) fr_type_is_float64((_x)->type)
471#define fr_box_is_date(_x) fr_type_is_date((_x)->type)
472#define fr_box_is_time_delta(_x) fr_type_is_time_delta((_x)->type)
473#define fr_box_is_size(_x) fr_type_is_size((_x)->type)
474#define fr_box_is_tlv(_x) fr_type_is_tlv((_x)->type)
475#define fr_box_is_struct(_x) fr_type_is_struct((_x)->type)
476#define fr_box_is_vsa(_x) fr_type_is_vsa((_x)->type)
477#define fr_box_is_vendor(_x) fr_type_is_vendor((_x)->type)
478#define fr_box_is_group(_x) fr_type_is_group((_x)->type)
479#define fr_box_is_value_box(_x) fr_type_is_value_box((_x)->type)
480#define fr_box_is_void(_x) fr_type_is_void((_x)->type)
482#define fr_box_is_integer_except_bool(_x) fr_type_is_integer_except_bool((_x)->type)
483#define fr_box_is_integer(_x) fr_type_is_integer((_x)->type)
484#define fr_box_is_numeric(_x) fr_type_is_numeric((_x)->type)
486#define fr_box_is_ip(_x) fr_type_is_ip((_x)->type)
488#define fr_box_is_fixed_size(_x) fr_type_is_fixed_size((_x)->type)
489#define fr_box_is_variable_size(_x) fr_type_is_variable_size((_x)->type)
490#define fr_box_is_value(_x) fr_type_is_value((_x)->type)
491#define fr_box_is_quoted(_x) fr_type_is_quoted((_x)->type)
493#define fr_box_is_structural_except_vsa(_x) fr_type_is_structural_except_vsa((_x)->type)
494#define fr_box_is_structural(_x) fr_type_is_structural((_x)->type)
495#define fr_box_is_non_value(_x) fr_type_is_non_value((_x)->type)
536#define FR_VALUE_BOX_INITIALISER_NULL(_vb) \
538 .type = FR_TYPE_NULL, \
540 .entry = FR_DLIST_ENTRY_INITIALISER((_vb).entry.entry) \
542 VALUE_BOX_NDEBUG_INITIALISER \
548#define FR_VALUE_BOX_INITIALISER(_vb, _type, _field, _val) \
555 .entry = FR_DLIST_ENTRY_INITIALISER((_vb).entry.entry) \
557 VALUE_BOX_NDEBUG_INITIALISER \
560static inline CC_HINT(
nonnull(1), always_inline)
579 .safety = { .secret = enumv && enumv->flags.secret },
582 fr_value_box_list_entry_init(vb);
590 fr_value_box_list_init(&vb->vb_group);
595 vb->vb_ip.af = AF_INET;
596 vb->vb_ip.prefix = 32;
601 vb->vb_ip.af = AF_INET;
605 vb->vb_ip.af = AF_INET6;
606 vb->vb_ip.prefix = 128;
610 vb->vb_ip.af = AF_INET6;
635#define fr_value_box_init(_vb, _type, _enumv, _tainted) _fr_value_box_init(NDEBUG_LOCATION_EXP _vb, _type, _enumv, _tainted)
641#define fr_value_box_init_null(_vb) _fr_value_box_init(NDEBUG_LOCATION_EXP _vb, FR_TYPE_NULL, NULL, false)
643static inline CC_HINT(always_inline)
669#define fr_value_box_alloc(_ctx, _type, _enumv) _fr_value_box_alloc(NDEBUG_LOCATION_EXP _ctx, _type, _enumv)
680#define fr_value_box_alloc_null(_ctx) _fr_value_box_alloc(NDEBUG_LOCATION_EXP _ctx, FR_TYPE_NULL, NULL)
744 unsigned int i = fr_value_box_list_num_elements(list);
761 CC_HINT(
nonnull(2,3)) CC_HINT(warn_unused_result);
775static inline CC_HINT(
nonnull(2))
804static inline CC_HINT(always_inline)
828static inline CC_HINT(always_inline)
862static inline CC_HINT(always_inline)
887static inline CC_HINT(
nonnull(1,3), always_inline) \
892 memcpy(dst->vb_ether, src,
sizeof(dst->vb_ether));
896#define DEF_BOXING_FUNC(_ctype, _field, _type) \
897static inline CC_HINT(nonnull(1), always_inline) \
898int fr_value_box_##_field(fr_value_box_t *dst, fr_dict_attr_t const *enumv, \
899 _ctype const value, bool tainted) { \
900 fr_value_box_init(dst, _type, enumv, tainted); \
901 dst->vb_##_field = value; \
936#define fr_value_box(_box, _var, _tainted) \
938 fr_ipaddr_t * : fr_value_box_ipaddr, \
939 fr_ipaddr_t const * : fr_value_box_ipaddr, \
940 fr_ethernet_t * : fr_value_box_ethernet_addr, \
941 fr_ethernet_t const * : fr_value_box_ethernet_addr, \
942 bool : fr_value_box_bool, \
943 uint8_t : fr_value_box_uint8, \
944 uint16_t : fr_value_box_uint16, \
945 uint32_t : fr_value_box_uint32, \
946 uint64_t : fr_value_box_uint64, \
947 int8_t : fr_value_box_int8, \
948 int16_t : fr_value_box_int16, \
949 int32_t : fr_value_box_int32, \
950 int64_t : fr_value_box_int64, \
951 float : fr_value_box_float32, \
952 double : fr_value_box_float64 \
953)(_box, NULL, _var, _tainted)
963#define fr_value_box_len(_ctx, _box, _var, _len, _tainted) \
965 char * : fr_value_box_bstrndup, \
966 char const * : fr_value_box_bstrndup, \
967 uint8_t * : fr_value_box_memdup, \
968 uint8_t const * : fr_value_box_memdup \
969)(_ctx, _box, NULL, _var, _len, _tainted)
983 fr_strerror_printf(
"Unboxing failed. Needed type %s, had type %s",
988 memcpy(dst, src->vb_ether,
sizeof(src->vb_ether));
992#define DEF_UNBOXING_FUNC(_ctype, _field, _type) \
993static inline CC_HINT(nonnull) \
994int fr_value_unbox_##_field(_ctype *var, fr_value_box_t const *src) { \
995 if (unlikely(src->type != _type)) { \
996 fr_strerror_printf("Unboxing failed. Needed type %s, had type %s", \
997 fr_type_to_str(_type), \
998 fr_type_to_str(src->type)); \
1001 *var = src->vb_##_field; \
1025#define fr_value_unbox_shallow(_var, _box) \
1027 uint8_t * : fr_value_unbox_uint8, \
1028 uint16_t * : fr_value_unbox_uint16, \
1029 uint32_t * : fr_value_unbox_uint32, \
1030 uint64_t * : fr_value_unbox_uint64, \
1031 int8_t * : fr_value_unbox_int8, \
1032 int16_t * : fr_value_unbox_int16, \
1033 int32_t * : fr_value_unbox_int32, \
1034 int64_t * : fr_value_unbox_int64, \
1035 float * : fr_value_unbox_float32, \
1036 double * : fr_value_unbox_float64 \
1062static inline
size_t fr_value_substr_aunescape(TALLOC_CTX *ctx,
char **
out,
fr_sbuff_t *
in,
size_t inlen,
char quote)
1072#define FR_VALUE_BOX_TO_NETWORK_RETURN(_dbuff, _value) FR_DBUFF_RETURN(fr_value_box_to_network, _dbuff, _value)
1079#define FR_VALUE_BOX_NET_ERROR SSIZE_MIN
1083#define FR_VALUE_BOX_NET_OOM (FR_VALUE_BOX_NET_ERROR + 1)
1087#define FR_VALUE_BOX_NET_MAX (FR_VALUE_BOX_NET_OOM + 1)
1095 int prefix_len,
uint8_t const *
data,
size_t data_len,
bool fixed,
bool tainted)
1100 void const *src,
size_t len)
1106 CC_HINT(warn_unused_result,
nonnull(2,5));
1110 CC_HINT(warn_unused_result,
nonnull(1));
1113 CC_HINT(warn_unused_result,
nonnull);
1125#define fr_value_box_mark_safe_for(_box, _safe_for) _fr_value_box_mark_safe_for(_box, (fr_value_box_safe_for_t)_safe_for)
1132#define fr_value_box_is_safe_for(_box, _safe_for) (((_box)->vb_safefor == (fr_value_box_safe_for_t)_safe_for) || ((_box)->vb_safefor == FR_VALUE_BOX_SAFE_FOR_ANY))
1133#define fr_value_box_is_safe_for_only(_box, _safe_for) ((_box)->vb_safefor == (fr_value_box_safe_for_t)_safe_for)
1143static inline CC_HINT(
nonnull, always_inline)
1146 return box->vb_secret;
1154 if (box->vb_secret)
return true;
1156 while ((vb = fr_value_box_list_next(&box->vb_group, vb))) {
1178static inline CC_HINT(
nonnull, always_inline)
1182 box->enumv && box->enumv->flags.has_value &&
1196 char const *src,
bool tainted)
1203 char const *
fmt, va_list ap)
1207 char const *
fmt, ...)
1211 char const *src,
bool tainted)
1226 size_t len,
bool tainted)
1233 char const *src,
size_t len,
bool tainted)
1241 char const *src,
bool tainted)
1245 char const *src,
size_t len,
bool tainted)
1249 char const *src,
bool tainted)
1259 size_t len,
bool tainted)
1266 uint8_t const *src,
size_t len,
bool tainted)
1274 uint8_t const *src,
bool tainted)
1278 uint8_t const *src,
size_t len,
bool tainted)
1282 uint8_t const *src,
bool tainted)
1294#define fr_value_box_get_cursor(_dst) talloc_get_type_abort((_dst)->vb_cursor, fr_dcursor_t)
1326 uint8_t const *sep,
size_t sep_len,
1364static inline CC_HINT(
nonnull(2,3))
1369static inline CC_HINT(
nonnull(2,3))
1383#if defined(WITH_VERIFY_PTR) || !defined(NDEBUG)
1389# define VALUE_BOX_VERIFY(_x) fr_value_box_verify(__FILE__, __LINE__, _x)
1390# define VALUE_BOX_LIST_VERIFY(_x) fr_value_box_list_verify(__FILE__, __LINE__, _x)
1397# define VALUE_BOX_VERIFY(_x) fr_assert(_x)
1398# define VALUE_BOX_LIST_VERIFY(_x) fr_assert(_x)
1399# define VALUE_BOX_VERIFY(_x) fr_assert(_x)
1400# define VALUE_BOX_LIST_VERIFY(_x) fr_assert(_x)
static int const char * fmt
#define UNCONST(_type, _ptr)
Remove const qualification from a pointer.
#define NDEBUG_LOCATION_VALS
#define NDEBUG_LOCATION_ARGS
Pass caller information to the function.
static size_t min(size_t x, size_t y)
#define FR_DCURSOR_DLIST_TYPES(_name, _list_name, _element_type)
Define type specific wrapper structs for dcursors.
#define FR_DCURSOR_FUNCS(_name, _list_name, _element_type)
Define type specific wrapper functions for dcursors.
#define da_is_bit_field(_da)
char const * fr_dict_enum_name_by_value(fr_dict_attr_t const *da, fr_value_box_t const *value)
Lookup the name of an enum value in a fr_dict_attr_t.
#define FR_DLIST_TYPES(_name)
Define type specific wrapper structs for dlists.
#define FR_DLIST_FUNCS(_name, _element_type, _element_entry)
Define type specific wrapper functions for dlists.
#define FR_DLIST_TYPEDEFS(_name, _head, _entry)
Define friendly names for type specific dlist head and entry structures.
Struct to represent an ethernet address.
Struct to represent an interface id.
@ FR_TYPE_FLOAT32
Single precision floating point.
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
@ FR_TYPE_INT8
8 Bit signed integer.
@ FR_TYPE_ETHERNET
48 Bit Mac-Address.
@ FR_TYPE_IPV6_PREFIX
IPv6 Prefix.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT16
16 Bit unsigned integer.
@ FR_TYPE_INT64
64 Bit signed integer.
@ FR_TYPE_INT16
16 Bit signed integer.
@ FR_TYPE_DATE
Unix time stamp, always has value >2^31.
@ FR_TYPE_COMBO_IP_PREFIX
IPv4 or IPv6 address prefix depending on length.
@ FR_TYPE_UINT8
8 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_INT32
32 Bit signed integer.
@ FR_TYPE_UINT64
64 Bit unsigned integer.
@ FR_TYPE_IPV6_ADDR
128 Bit IPv6 Address.
@ FR_TYPE_IPV4_PREFIX
IPv4 Prefix.
@ FR_TYPE_BOOL
A truth value.
@ FR_TYPE_COMBO_IP_ADDR
IPv4 or IPv6 address depending on length.
@ FR_TYPE_GROUP
A grouping of other attributes.
@ FR_TYPE_FLOAT64
Double precision floating point.
fr_cmp_ret_t
Result of an ordering comparison.
#define SBUFF_OUT_TALLOC_FUNC_NO_LEN_DEF(_func,...)
#define SBUFF_OUT_TALLOC_FUNC_DEF(_func, _in, _len,...)
Set of parsing rules for *unescape_until functions.
fr_aka_sim_id_type_t type
A time delta, a difference in time measured in nanoseconds.
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
#define FR_TYPE_STRUCTURAL
#define fr_type_is_leaf(_x)
static char const * fr_type_to_str(fr_type_t type)
Return a static string containing the type name.
int fr_value_box_bstrndup_replace(TALLOC_CTX *ctx, fr_value_box_t *vb, char const *src, ssize_t len))
Free the existing buffer (if talloced) associated with the valuebox, and replace it with a copy of a ...
fr_value_box_list_action_t
Actions to perform when we process a box in a list.
@ FR_VALUE_BOX_LIST_NONE
Do nothing to processed boxes.
@ FR_VALUE_BOX_LIST_REMOVE
Remove the box from the input list.
@ FR_VALUE_BOX_LIST_FREE_BOX_VALUE
Explicitly free any value buffers associated with a box.
@ FR_VALUE_BOX_LIST_FREE_BOX
Free each processed box.
fr_cmp_ret_t fr_value_box_cmp(fr_value_box_t const *a, fr_value_box_t const *b)
Compare two values.
size_t const fr_value_box_field_sizes[]
How many bytes wide each of the value data fields are.
size_t fr_value_box_network_length(fr_value_box_t const *value)
Get the size of the value held by the fr_value_box_t.
int fr_value_box_vasprintf(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, bool tainted, char const *fmt, va_list ap)
void fr_value_box_set_void_shallow(fr_value_box_t *dst, void const *ptr)
Assign a void pointer to a box.
int(* fr_value_box_escape_func_t)(fr_value_box_t *vb, void *uctx)
Escape a value box.
fr_ifid_t ifid
IPv6 interface ID.
fr_sbuff_unescape_rules_t const fr_value_unescape_single
ssize_t fr_value_box_list_concat_as_octets(fr_value_box_safety_t *safety, fr_dbuff_t *dbuff, fr_value_box_list_t *list, uint8_t const *sep, size_t sep_len, fr_value_box_list_action_t proc_action, bool flatten))
Concatenate a list of value boxes together.
uint16_t uint16
16bit unsigned integer.
#define DEF_UNBOXING_FUNC(_ctype, _field, _type)
uint32_t fr_value_box_hash(fr_value_box_t const *vb)
Hash the contents of a value box.
static int fr_value_box_memcpy_out(void *out, fr_value_box_t const *vb)
Copy the value of a value box to a field in a C struct.
char * fr_value_box_list_aprint_secure(TALLOC_CTX *ctx, fr_value_box_list_t const *list, char const *delim, fr_sbuff_escape_rules_t const *e_rules))
Concatenate the string representations of a list of value boxes together hiding "secret" values.
int fr_value_box_escape_in_place(fr_value_box_t *vb, fr_value_box_escape_t const *escape, void *uctx))
Escape a single value box in place.
int8_t int8
8bit signed integer.
fr_value_box_safe_for_t safe_for
A unique value to indicate if that value box is safe for consumption by a particular module for a par...
fr_sbuff_escape_rules_t const fr_value_escape_double
fr_sbuff_parse_rules_t const value_parse_rules_single_3quoted
static fr_slen_t fr_value_box_aprint(TALLOC_CTX *ctx, char **out, fr_value_box_t const *data, fr_sbuff_escape_rules_t const *e_rules) 1(fr_value_box_print
static bool fr_value_box_is_secret(fr_value_box_t const *box)
fr_sbuff_escape_rules_t const fr_value_escape_backtick
int fr_value_box_escape_erules(fr_value_box_t *vb, void *uctx)
Escape a value-box in place using the supplied fr_sbuff_escape_rules_t in uctx.
#define DEF_BOXING_FUNC(_ctype, _field, _type)
fr_sbuff_escape_rules_t const fr_value_escape_secret
Escape secret fields by simply mashing all data to '.
int fr_value_box_list_concat_in_place(TALLOC_CTX *ctx, fr_value_box_t *out, fr_value_box_list_t *list, fr_type_t type, fr_value_box_list_action_t proc_action, bool flatten, size_t max_size))
Concatenate a list of value boxes.
fr_sbuff_parse_rules_t const value_parse_rules_double_unquoted
size_t size
System specific file/memory size.
fr_sbuff_parse_rules_t const value_parse_rules_solidus_quoted
int fr_value_box_cast(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, fr_value_box_t const *src))
Convert one type of fr_value_box_t to another.
fr_sbuff_escape_rules_t const fr_value_escape_unprintables
static bool fr_value_box_contains_secret(fr_value_box_t const *box)
unsigned int secret
Same as fr_dict_attr_flags_t secret.
fr_value_box_list_t children
for groups
int fr_value_box_copy(TALLOC_CTX *ctx, fr_value_box_t *dst, const fr_value_box_t *src))
Copy value data verbatim duplicating any buffers.
int fr_value_box_bstrndup_dbuff(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, fr_dbuff_t *dbuff, size_t len, bool tainted))
int fr_value_box_asprintf(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, bool tainted, char const *fmt,...)
int fr_value_box_strdup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, bool tainted))
Copy a nul terminated string to a fr_value_box_t.
static bool fr_value_box_list_len_min(fr_value_box_list_t const *list, unsigned int min)
Determines whether a list contains the number of boxes required.
fr_type_t _CONST type
Type and flags should appear together for packing efficiency.
fr_sbuff_parse_rules_t const * value_parse_rules_quoted[T_TOKEN_LAST]
Parse rules for quoted strings.
static fr_value_box_t * fr_value_box_acopy(TALLOC_CTX *ctx, fr_value_box_t const *src)
Copy an existing box, allocating a new box to hold its contents.
fr_dict_attr_t const * da
dictionary reference
static uint8_t * fr_value_box_raw(fr_value_box_t const *vb, fr_type_t type)
Return a pointer to the "raw" value from a value-box.
fr_sbuff_escape_rules_t const fr_value_escape_solidus
float float32
Single precision float.
fr_sbuff_unescape_rules_t const * fr_value_unescape_by_quote[T_TOKEN_LAST]
fr_value_box_safety_t _CONST safety
Safety of the value, see fr_value_box_safety_t.
size_t const fr_value_box_offsets[]
Where the value starts in the fr_value_box_t.
#define FR_VALUE_BOX_MAGIC
int fr_value_box_mem_alloc(TALLOC_CTX *ctx, uint8_t **out, fr_value_box_t *dst, fr_dict_attr_t const *enumv, size_t len, bool tainted))
Pre-allocate an octets buffer for filling by the caller.
fr_sbuff_parse_rules_t const value_parse_rules_bareword_unquoted
Default formatting rules.
int fr_value_box_escape_in_place_func(TALLOC_CTX *ctx, fr_value_box_t *vb, fr_sbuff_escape_func_t escape)
Escape a value box in place using an sbuff escape function.
int fr_value_box_strtrim(TALLOC_CTX *ctx, fr_value_box_t *vb))
Trim the length of the string buffer to match the length of the C string.
int fr_value_box_ipaddr(fr_value_box_t *dst, fr_dict_attr_t const *enumv, fr_ipaddr_t const *ipaddr, bool tainted))
Assign a fr_value_box_t value from an fr_ipaddr_t.
fr_sbuff_parse_rules_t const value_parse_rules_single_unquoted
int fr_value_box_cmp_op(fr_token_t op, fr_value_box_t const *a, fr_value_box_t const *b)
Compare two attributes using an operator.
unsigned int immutable
once set, the value cannot be changed
int fr_value_box_memdup_dbuff(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, fr_dbuff_t *dbuff, size_t len, bool tainted))
fr_unix_time_t date
Date internal format in nanoseconds.
fr_sbuff_parse_rules_t const * value_parse_rules_unquoted_char[SBUFF_CHAR_CLASS]
uint64_t magic
Value to verify that the structure was allocated or initialised properly.
fr_ipaddr_t ip
IPv4/6 address/prefix.
fr_sbuff_parse_rules_t const value_parse_rules_single_quoted
int32_t int32
32bit signed integer.
int fr_value_box_mem_realloc(TALLOC_CTX *ctx, uint8_t **out, fr_value_box_t *dst, size_t len))
Change the length of a buffer already allocated to a value box.
void fr_value_box_memdup_shallow(fr_value_box_t *dst, fr_dict_attr_t const *enumv, uint8_t const *src, size_t len, bool tainted))
Assign a buffer to a box, but don't copy it.
ssize_t fr_value_box_list_concat_as_string(fr_value_box_safety_t *safety, fr_sbuff_t *sbuff, fr_value_box_list_t *list, char const *sep, size_t sep_len, fr_sbuff_escape_rules_t const *e_rules, fr_value_box_list_action_t proc_action, fr_value_box_safe_for_t safe_for, bool flatten))
Concatenate a list of value boxes together.
char const * file
File where the box was allocated or initialised.
void fr_value_box_increment(fr_value_box_t *vb)
Increment a boxed value.
size_t fr_value_str_unescape(fr_sbuff_t *out, fr_sbuff_t *in, size_t inlen, char quote)
Convert a string value with escape sequences into its binary form.
void fr_value_box_set_attr(fr_value_box_t *dst, fr_dict_attr_t const *da)
int fr_value_box_memdup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, uint8_t const *src, size_t len, bool tainted))
Copy a buffer to a fr_value_box_t.
void fr_value_box_set_cursor_shallow(fr_value_box_t *dst, fr_type_t type, void *ptr, char const *name)
fr_sbuff_unescape_rules_t const fr_value_unescape_backtick
void fr_value_box_set_secret(fr_value_box_t *box, bool secret)
Mark a box as holding a secret, or not.
static size_t char fr_sbuff_t size_t inlen
void fr_value_box_list_verify(char const *file, int line, fr_value_box_list_t const *list))
fr_value_box_safe_for_t safe_for
fr_sbuff_parse_rules_t const * value_parse_rules_3quoted[T_TOKEN_LAST]
void fr_value_box_flatten(TALLOC_CTX *ctx, fr_value_box_list_t *list, bool steal, bool free))
Removes a single layer of nesting, moving all children into the parent list.
void fr_value_box_strdup_shallow_replace(fr_value_box_t *vb, char const *src, ssize_t len)
Free the existing buffer (if talloced) associated with the valuebox, and replace it with a new one.
void fr_value_box_safety_set(fr_value_box_t *box, fr_value_box_safety_t const *safety)
Replace the safety of a box.
fr_sbuff_unescape_rules_t const fr_value_unescape_double
void _fr_value_box_mark_safe_for(fr_value_box_t *box, fr_value_box_safe_for_t safe_for)
Mark a value-box as "safe", of a particular type.
void fr_value_box_clear_value(fr_value_box_t *data))
Clear/free any existing value.
ssize_t fr_value_box_from_network(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t type, fr_dict_attr_t const *enumv, fr_dbuff_t *dbuff, size_t len, bool tainted))
Decode a fr_value_box_t from serialized binary data.
static int fr_value_box_memcpy_in(fr_value_box_t *vb, void const *in)
Copy a C value value to a value box.
ssize_t fr_value_box_print_quoted(fr_sbuff_t *out, fr_value_box_t const *data, fr_token_t quote)
Print one boxed value to a string with quotes (where needed)
bool boolean
A truth value.
fr_sbuff_parse_rules_t const value_parse_rules_double_3quoted
static always_inline void _fr_value_box_init(NDEBUG_LOCATION_ARGS fr_value_box_t *vb, fr_type_t type, fr_dict_attr_t const *enumv, bool tainted)
static size_t fr_value_str_aunescape(TALLOC_CTX *ctx, char **out, fr_sbuff_t *in, size_t inlen, char quote) static inline size_t fr_value_substr_aunescape(TALLOC_CTX *ctx
int line
Line where the box was allocated or initialised.
static char const * fr_value_box_enum_name(fr_value_box_t const *box)
Decide if we need an enum prefix.
bool fr_value_box_list_tainted(fr_value_box_list_t const *head))
Check to see if any list members (or their children) are tainted.
void fr_value_box_safety_copy_changed(fr_value_box_t *out, fr_value_box_t const *in)
Copy the safety values from one box to another.
fr_dict_attr_t const * enumv
Enumeration values.
bool fr_value_box_is_truthy(fr_value_box_t const *box))
Check truthiness of values.
void fr_value_box_verify(char const *file, int line, fr_value_box_t const *vb))
Validation function to check that a fr_value_box_t is correctly initialised.
uintptr_t fr_value_box_safe_for_t
Escaping that's been applied to a value box.
void fr_value_box_list_mark_safe_for(fr_value_box_list_t *list, fr_value_box_safe_for_t safe_for)
Set the escaped flag for all value boxes in a list.
int fr_value_unbox_ipaddr(fr_ipaddr_t *dst, fr_value_box_t *src)
Unbox an IP address performing a type check.
fr_slen_t fr_value_box_from_str(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, char const *in, size_t inlen, fr_sbuff_unescape_rules_t const *erules))
int fr_value_box_cast_in_place(TALLOC_CTX *ctx, fr_value_box_t *vb, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv))
Convert one type of fr_value_box_t to another in place.
int fr_value_box_escape_in_place_erules(TALLOC_CTX *ctx, fr_value_box_t *vb, fr_sbuff_escape_rules_t const *erules)
Escape a value-box in place using sbuff escaping rules, and mark it safe-for.
fr_sbuff_parse_rules_t const value_parse_rules_bareword_quoted
void fr_value_box_safety_merge(fr_value_box_t *out, fr_value_box_t const *in)
Merge safety results.
fr_sbuff_parse_rules_t const value_parse_rules_backtick_3quoted
fr_sbuff_escape_rules_t const fr_value_escape_single
fr_value_box_entry_t entry
Doubly linked list entry.
int fr_value_box_list_escape_in_place(fr_value_box_list_t *list, fr_value_box_escape_t const *escape, void *uctx))
Escape a list of value boxes in place.
fr_ethernet_t ether
Ethernet (MAC) address.
void fr_value_box_list_debug(FILE *fp, fr_value_box_list_t const *head)
Print a list of value boxes as info messages.
fr_sbuff_parse_rules_t const * value_parse_rules_quoted_char[SBUFF_CHAR_CLASS]
fr_sbuff_parse_rules_t const value_parse_rules_solidus_unquoted
uint64_t fr_value_box_as_uint64(fr_value_box_t const *src)
Return a uint64_t from a fr_value_box_t.
fr_sbuff_parse_rules_t const value_parse_rules_backtick_quoted
fr_value_box_datum_t datum
The value held by the value box.
fr_sbuff_parse_rules_t const * value_parse_rules_unquoted[T_TOKEN_LAST]
Parse rules for non-quoted strings.
unsigned int talloced
Talloced, not stack or text allocated.
double float64
Double precision float.
#define fr_value_box_alloc_null(_ctx)
Allocate a value box for later use with a value assignment function.
uint64_t uint64
64bit unsigned integer.
void fr_value_box_strdup_shallow(fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, bool tainted))
Assign a buffer containing a nul terminated string to a box, but don't copy it.
int fr_value_box_bstrdup_buffer(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, bool tainted))
Copy a nul terminated talloced buffer to a fr_value_box_t.
int fr_value_box_bstrdup_buffer_shallow(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, bool tainted))
Assign a talloced buffer containing a nul terminated string to a box, but don't copy it.
static fr_slen_t static e_rules fr_slen_t fr_value_box_aprint_quoted(TALLOC_CTX *ctx, char **out, fr_value_box_t const *data, fr_token_t quote) 1(fr_value_box_print_quoted
void fr_value_box_safety_copy(fr_value_box_t *out, fr_value_box_t const *in)
Copy the safety values from one box to another.
unsigned int tainted
i.e. did it come from an untrusted source
fr_sbuff_parse_rules_t const value_parse_rules_backtick_unquoted
fr_sbuff_parse_rules_t const value_parse_rules_double_quoted
void fr_value_box_memdup_buffer_shallow(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, uint8_t const *src, bool tainted))
Assign a talloced buffer to a box, but don't copy it.
static size_t char fr_sbuff_t * in
fr_sbuff_parse_rules_t const value_parse_rules_solidus_3quoted
uint32_t uint32
32bit unsigned integer.
int fr_value_box_bstr_realloc(TALLOC_CTX *ctx, char **out, fr_value_box_t *dst, size_t len))
Change the length of a buffer already allocated to a value box.
unsigned int edit
to control foreach / edits
static size_t char fr_sbuff_t size_t char quote int fr_value_box_hton(fr_value_box_t *dst, fr_value_box_t const *src)
Performs byte order reversal for types that need it.
uint128_t uint128
128bit unsigned integer.
int fr_value_box_to_key(uint8_t **out, size_t *outlen, fr_value_box_t const *value)
Get a key from a value box.
fr_value_box_escape_func_t func
void fr_value_box_bstrndup_shallow(fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, size_t len, bool tainted))
Assign a string to to a fr_value_box_t.
int16_t int16
16bit signed integer.
ssize_t fr_value_box_from_memory(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t type, fr_dict_attr_t const *enumv, void const *src, size_t len))
Decode a fr_value_box_t from a C type in memory.
int fr_value_box_bstrndup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, size_t len, bool tainted))
Copy a string to to a fr_value_box_t.
ssize_t fr_value_box_to_network(fr_dbuff_t *dbuff, fr_value_box_t const *value)
Encode a single value box, serializing its contents in generic network format.
void fr_value_box_list_safety_merge(fr_value_box_t *out, fr_value_box_list_t const *list)
Set the safety of out to the most restrictive safety of any leaf box in a list.
void fr_value_box_copy_shallow(TALLOC_CTX *ctx, fr_value_box_t *dst, const fr_value_box_t *src))
Perform a shallow copy of a value_box.
static always_inline int fr_value_box_ethernet_addr(fr_value_box_t *dst, fr_dict_attr_t const *enumv, fr_ethernet_t const *src, bool tainted)
fr_sbuff_unescape_rules_t const * fr_value_unescape_by_char[SBUFF_CHAR_CLASS]
void fr_value_box_debug(FILE *fp, fr_value_box_t const *vb)
Print the value of a box as info messages.
fr_slen_t fr_value_box_from_substr(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *rules))
Convert string value to a fr_value_box_t type.
char * fr_value_box_list_aprint(TALLOC_CTX *ctx, fr_value_box_list_t const *list, char const *delim, fr_sbuff_escape_rules_t const *e_rules))
Concatenate the string representations of a list of value boxes together.
static fr_value_box_t * _fr_value_box_alloc(NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx, fr_type_t type, fr_dict_attr_t const *enumv)
static int fr_value_unbox_ethernet_addr(fr_ethernet_t *dst, fr_value_box_t *src)
Unbox an ethernet value (6 bytes, network byte order)
fr_sbuff_unescape_rules_t const fr_value_unescape_solidus
#define fr_value_box_init(_vb, _type, _enumv, _tainted)
Initialise a fr_value_box_t.
void fr_value_box_clear(fr_value_box_t *data))
Clear/free any existing value and metadata.
fr_sbuff_escape_rules_t const * fr_value_escape_by_quote[T_TOKEN_LAST]
ssize_t fr_value_box_ipaddr_from_network(fr_value_box_t *dst, fr_type_t type, fr_dict_attr_t const *enumv, int prefix_len, uint8_t const *data, size_t data_len, bool fixed, bool tainted))
Decode a fr_value_box_t of type IP address / prefix.
void fr_value_box_mark_unsafe(fr_value_box_t *box)
Mark a value-box as "unsafe".
uint8_t uint8
8bit unsigned integer.
int fr_value_box_memdup_buffer(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, uint8_t const *src, bool tainted))
Copy a talloced buffer to a fr_value_box_t.
int format(printf, 5, 0))
size_t fr_value_substr_unescape(fr_sbuff_t *out, fr_sbuff_t *in, size_t inlen, char quote)
Convert a string value with escape sequences into its binary form.
static size_t char ** out
int fr_value_box_list_acopy(TALLOC_CTX *ctx, fr_value_box_list_t *out, fr_value_box_list_t const *in))
Do a full copy of a list of value boxes.
fr_sbuff_escape_rules_t const * fr_value_escape_by_char[SBUFF_CHAR_CLASS]
ssize_t fr_value_box_print(fr_sbuff_t *out, fr_value_box_t const *data, fr_sbuff_escape_rules_t const *e_rules))
Print one boxed value to a string.
int fr_value_box_bstr_alloc(TALLOC_CTX *ctx, char **out, fr_value_box_t *dst, fr_dict_attr_t const *enumv, size_t len, bool tainted))
Alloc and assign an empty \0 terminated string to a fr_value_box_t.
fr_time_delta_t time_delta
a delta time in nanoseconds
int64_t int64
64bit signed integer;
int fr_value_box_steal(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t *src))
Copy value data verbatim moving any buffers to the specified context.
Union containing all data types supported by the server.