45 RCSID(
"$Id: 4e62462ed2d28ca6816953fa24d4c423134a9a3d $")
47 #define _VALUE_PRIVATE
48 #include <freeradius-devel/util/value.h>
51 #include <freeradius-devel/util/atexit.h>
52 #include <freeradius-devel/util/base16.h>
53 #include <freeradius-devel/util/dcursor.h>
54 #include <freeradius-devel/util/size.h>
55 #include <freeradius-devel/util/time.h>
64 "in_addr.s_addr has unexpected length");
66 "in6_addr.s6_addr has unexpected length");
68 "vb_ifid has unexpected length");
70 "vb_ether has unexpected length");
73 "datum.boolean has unexpected length");
75 "vb_uint8 has unexpected length");
77 "vb_uint16 has unexpected length");
79 "vb_uint32 has unexpected length");
81 "vb_uint64 has unexpected length");
84 "vb_int16 has unexpected length");
86 "vb_int16 has unexpected length");
88 "vb_int32 has unexpected length");
90 "vb_int64 has unexpected length");
93 "vb_float32 has unexpected length");
95 "vb_float64 has unexpected length");
107 #define network_min_size(_x) (fr_value_box_network_sizes[_x][0])
108 #define network_max_size(_x) (fr_value_box_network_sizes[_x][1])
373 #pragma clang diagnostic ignored "-Wgnu-designator"
456 .name =
"unprintables",
550 L(
""),
L(
"\n"),
L(
"\r"),
L(
"\""))
556 L(
""),
L(
"\n"),
L(
"\r"),
L(
"'"))
562 L(
""),
L(
"\n"),
L(
"\r"),
L(
"/"))
568 L(
""),
L(
"\n"),
L(
"\r"),
L(
"`"))
606 dst->vb_length = src->vb_length;
615 fr_value_box_list_init(&dst->vb_group);
622 dst->enumv = src->enumv;
623 dst->type = src->type;
624 dst->tainted = src->tainted;
625 dst->safe_for = src->safe_for;
626 dst->secret = src->secret;
627 fr_value_box_list_entry_init(dst);
645 if (a->type != b->type) {
659 if (a->vb_length < b->vb_length) {
660 length = a->vb_length;
662 length = b->vb_length;
666 int cmp = memcmp(a->datum.ptr, b->datum.ptr, length);
667 if (cmp != 0)
return CMP(cmp, 0);
676 return CMP(a->vb_length, b->vb_length);
682 #define RETURN(_type) return CMP(a->datum._type, b->datum._type)
683 #define COMPARE(_type) return CMP(memcmp(&a->datum._type, &b->datum._type, sizeof(a->datum._type)), 0)
772 if (a_net == b_net) {
775 compare = memcmp(a, b, bytes);
781 if ((compare == 0) &&
843 if (common == 0)
return true;
848 if (common < 8)
break;
850 if (a[i] != b[i])
return false;
858 mask <<= (8 - common);
862 if ((a[i] &
mask) == ((b[i] &
mask))) {
897 if (b->vb_ip.af != AF_INET)
goto fail_cmp_v4;
904 if (b->vb_ip.af != AF_INET)
goto fail_cmp_v4;
909 b->vb_ip.prefix, (
uint8_t const *) &b->vb_ip.addr.v4.s_addr);
921 if (b->vb_ip.af != AF_INET)
goto fail_cmp_v4;
926 (
uint8_t const *) &a->vb_ip.addr.v4.s_addr,
927 32, (
uint8_t const *) &b->vb_ip.addr.v4);
930 if (b->vb_ip.af != AF_INET)
goto fail_cmp_v4;
935 (
uint8_t const *) &a->vb_ip.addr.v4.s_addr,
936 b->vb_ip.prefix, (
uint8_t const *) &b->vb_ip.addr.v4.s_addr);
946 if (b->vb_ip.af != AF_INET6)
goto fail_cmp_v6;
953 if (b->vb_ip.af != AF_INET6)
goto fail_cmp_v6;
958 b->vb_ip.prefix, (
uint8_t const *) &b->vb_ip.addr.v6);
970 if (b->vb_ip.af != AF_INET6)
goto fail_cmp_v6;
975 (
uint8_t const *) &a->vb_ip.addr.v6,
976 128, (
uint8_t const *) &b->vb_ip.addr.v6);
979 if (b->vb_ip.af != AF_INET6)
goto fail_cmp_v6;
984 (
uint8_t const *) &a->vb_ip.addr.v6,
985 b->vb_ip.prefix, (
uint8_t const *) &b->vb_ip.addr.v6);
993 if (a->vb_ip.af != b->vb_ip.af)
goto fail_cmp_v4;
998 if (a->vb_ip.af != b->vb_ip.af)
goto fail_cmp_v4;
1000 if (a->vb_ip.af == AF_INET)
goto cmp_prefix_v4;
1017 return (compare == 0);
1020 return (compare != 0);
1023 return (compare < 0);
1026 return (compare > 0);
1029 return (compare <= 0);
1032 return (compare >= 0);
1190 switch (src->type) {
1227 switch (src->type) {
1229 dst->vb_uint16 = htons(src->vb_uint16);
1233 dst->vb_uint32 = htonl(src->vb_uint32);
1237 dst->vb_uint64 = htonll(src->vb_uint64);
1241 dst->vb_int16 = htons(src->vb_int16);
1245 dst->vb_int32 = htonl(src->vb_int32);
1249 dst->vb_int64 = htonll(src->vb_int64);
1261 dst->vb_float32 = htonl((
uint32_t)src->vb_float32);
1265 dst->vb_float64 = htonll((uint64_t)src->vb_float64);
1282 switch (
value->type) {
1288 if (
value->enumv->flags.length) {
1289 return value->enumv->flags.length;
1297 if (
value->vb_length > 255)
return 255;
1300 if (
value->vb_length > 65535)
return 65535;
1304 return value->vb_length;
1311 if (
value->enumv)
return value->enumv->flags.length;
1378 switch (
value->type) {
1381 max =
value->vb_length;
1388 if (
value->enumv->flags.length) {
1392 if (max < value->enumv->flags.length) {
1397 }
else if (max >
value->enumv->flags.length) {
1401 max =
value->enumv->flags.length;
1409 if (max > 255) max = 255;
1413 if (max > 65536) max = 65535;
1447 switch (
value->type) {
1452 sizeof(
value->vb_ip.addr.v4.s_addr));
1462 sizeof(
value->vb_ip.addr.v4.s_addr));
1483 switch (
value->vb_ip.af) {
1498 switch (
value->vb_ip.af) {
1553 if (!
value->enumv) {
1556 res =
value->enumv->flags.flag_time_res;
1560 if (!
value->enumv) {
1563 }
else switch (
value->enumv->flags.length) {
1565 if (date > UINT16_MAX) date = UINT16_MAX;
1571 if (date > UINT32_MAX) date = UINT32_MAX;
1590 if (
value->enumv) res =
value->enumv->flags.flag_time_res;
1594 if (!
value->enumv) {
1597 }
else if (!
value->enumv->flags.is_unsigned) {
1598 switch (
value->enumv->flags.length) {
1600 if (date < INT16_MIN) {
1602 }
else if (date > INT16_MAX) {
1610 if (date < INT32_MIN) {
1612 }
else if (date > INT32_MAX) {
1626 switch (
value->enumv->flags.length) {
1630 }
else if (date > UINT16_MAX) {
1639 }
else if (date > UINT32_MAX) {
1722 "Expected length >= %zu bytes, got %zu bytes",
1732 if (enumv && !enumv->flags.array) {
1734 "Expected length <= %zu bytes, got %zu bytes",
1747 size_t newlen = len;
1754 if (enumv->flags.length) {
1755 newlen = enumv->flags.length;
1786 if (newlen > len)
return -(newlen + offset);
1844 dst->vb_ip.scope_id = scope_id;
1860 dst->vb_ip.scope_id = scope_id;
1888 dst->datum.boolean = (val != 0);
1951 length = enumv->flags.length;
1959 if (len > length)
return -(length);
1981 length = enumv->flags.length;
1989 if (len > length)
return -(length);
1993 if (!enumv || !enumv->flags.is_unsigned) {
2005 if (tmp > INT64_MAX) tmp = INT64_MAX;
2044 switch (
value->type) {
2046 if (*outlen < 8)
return -1;
2061 if (slen < 0)
return slen;
2070 *outlen =
value->vb_ip.prefix;
2076 *outlen =
value->vb_length * 8;
2081 *outlen =
sizeof(
value->vb_ether) * 8;
2109 fr_strerror_printf(
"Invalid cast from %s to %s. Source is length %zd is smaller than "
2110 "destination type size %zd",
2120 "destination type size %zd",
2145 0x00, 0x00, 0x00, 0x00, 0xff, 0xff };
2164 switch (src->type) {
2171 (
char const *)src->vb_octets, src->vb_length, src->tainted);
2175 dst,
UNCONST(fr_value_box_list_t *, &src->vb_group),
2211 switch (src->type) {
2217 (
uint8_t const *)src->vb_strvalue, src->vb_length, src->tainted) < 0) {
2224 dst,
UNCONST(fr_value_box_list_t *, &src->vb_group),
2233 (
uint8_t const *)&src->vb_ip.addr.v4.s_addr,
2234 sizeof(src->vb_ip.addr.v4.s_addr), src->tainted);
2244 sizeof(src->vb_ip.addr.v4.s_addr) + 1, src->tainted) < 0)
return -1;
2246 bin[0] = src->vb_ip.prefix;
2247 memcpy(&bin[1], (
uint8_t const *)&src->vb_ip.addr.v4.s_addr,
sizeof(src->vb_ip.addr.v4.s_addr));
2256 (
uint8_t const *)src->vb_ip.addr.v6.s6_addr,
2257 sizeof(src->vb_ip.addr.v6.s6_addr), src->tainted);
2267 sizeof(src->vb_ip.addr.v6.s6_addr) + 2, src->tainted) < 0)
return -1;
2268 bin[0] = src->vb_ip.scope_id;
2269 bin[1] = src->vb_ip.prefix;
2270 memcpy(&bin[2], src->vb_ip.addr.v6.s6_addr,
sizeof(src->vb_ip.addr.v6.s6_addr));
2295 #define CAST_IP_FIX_COMBO \
2296 case FR_TYPE_COMBO_IP_ADDR: \
2297 if (src->vb_ip.af == AF_INET) { \
2298 src_type = FR_TYPE_IPV4_ADDR; \
2299 } else if (src->vb_ip.af == AF_INET6) { \
2300 src_type = FR_TYPE_IPV6_ADDR; \
2303 case FR_TYPE_COMBO_IP_PREFIX: \
2304 if (src->vb_ip.af == AF_INET) { \
2305 src_type = FR_TYPE_IPV4_PREFIX; \
2306 } else if (src->vb_ip.af == AF_INET6) { \
2307 src_type = FR_TYPE_IPV6_PREFIX; \
2338 src->vb_strvalue, src->vb_length,
2339 NULL, src->tainted);
2351 dst->vb_ip.af = AF_INET;
2352 dst->vb_ip.prefix = 32;
2353 dst->vb_ip.scope_id = 0;
2365 memcpy(&dst->vb_ip.addr.v4, &src->vb_ip.addr.v6.s6_addr[
sizeof(
v4_v6_map)],
2366 sizeof(dst->vb_ip.addr.v4));
2371 if (src->vb_ip.prefix != 32) {
2373 "cast to IP address types",
2382 memcpy(&dst->vb_ip.addr.v4, &src->vb_ip.addr.v4,
sizeof(dst->vb_ip.addr.v4));
2386 if (src->vb_ip.prefix != 128) {
2387 fr_strerror_printf(
"Invalid cast from %s to %s. Only /128 (not /%i) prefixes may be "
2388 "cast to IP address types",
2394 if (memcmp(&src->vb_ip.addr.v6.s6_addr,
v4_v6_map,
sizeof(
v4_v6_map)) != 0)
goto bad_v6_prefix_map;
2395 memcpy(&dst->vb_ip.addr.v4, &src->vb_ip.addr.v6.s6_addr[
sizeof(
v4_v6_map)],
2396 sizeof(dst->vb_ip.addr.v4));
2400 if (src->vb_length !=
sizeof(dst->vb_ip.addr.v4.s_addr)) {
2401 fr_strerror_printf(
"Invalid cast from %s to %s. Needed octet string of length %zu, got %zu",
2404 sizeof(dst->vb_ip.addr.v4.s_addr), src->vb_length);
2407 memcpy(&dst->vb_ip.addr.v4, src->vb_octets,
sizeof(dst->vb_ip.addr.v4.s_addr));
2414 net = ntohl(src->vb_uint32);
2415 memcpy(&dst->vb_ip.addr.v4, (
uint8_t *)&net,
sizeof(dst->vb_ip.addr.v4.s_addr));
2453 src->vb_strvalue, src->vb_length,
2454 NULL, src->tainted);
2466 dst->vb_ip.af = AF_INET;
2467 dst->vb_ip.scope_id = 0;
2471 dst->vb_ip.prefix = src->vb_ip.prefix;
2475 memcpy(&dst->vb_ip, &src->vb_ip,
sizeof(dst->vb_ip));
2489 memcpy(&dst->vb_ip.addr.v4.s_addr, &src->vb_ip.addr.v6.s6_addr[
sizeof(
v4_v6_map)],
2490 sizeof(dst->vb_ip.addr.v4.s_addr));
2491 dst->vb_ip.prefix = 32;
2495 if (memcmp(src->vb_ip.addr.v6.s6_addr,
v4_v6_map,
sizeof(
v4_v6_map)) != 0)
goto bad_v6_prefix_map;
2497 if (src->vb_ip.prefix < (
sizeof(
v4_v6_map) << 3)) {
2498 fr_strerror_printf(
"Invalid cast from %s to %s. Expected prefix >= %u bits got %u bits",
2501 (
unsigned int)(
sizeof(
v4_v6_map) << 3), src->vb_ip.prefix);
2504 memcpy(&dst->vb_ip.addr.v4.s_addr, &src->vb_ip.addr.v6.s6_addr[
sizeof(
v4_v6_map)],
2505 sizeof(dst->vb_ip.addr.v4.s_addr));
2510 dst->vb_ip.prefix = src->vb_ip.prefix - (
sizeof(
v4_v6_map) << 3);
2514 if (src->vb_length !=
sizeof(dst->vb_ip.addr.v4.s_addr) + 1) {
2515 fr_strerror_printf(
"Invalid cast from %s to %s. Needed octet string of length %zu, got %zu",
2518 sizeof(dst->vb_ip.addr.v4.s_addr) + 1, src->vb_length);
2521 dst->vb_ip.prefix = src->vb_octets[0];
2522 memcpy(&dst->vb_ip.addr.v4, &src->vb_octets[1],
sizeof(dst->vb_ip.addr.v4.s_addr));
2529 net = ntohl(src->vb_uint32);
2530 memcpy(&dst->vb_ip.addr.v4, (
uint8_t *)&net,
sizeof(dst->vb_ip.addr.v4.s_addr));
2531 dst->vb_ip.prefix = 32;
2566 sizeof(src->vb_ip.addr.v6),
"IPv6 storage too small");
2572 src->vb_strvalue, src->vb_length,
2573 NULL, src->tainted);
2585 dst->vb_ip.af = AF_INET6;
2586 dst->vb_ip.prefix = 128;
2591 uint8_t *p = dst->vb_ip.addr.v6.s6_addr;
2596 memcpy(p, (
uint8_t const *)&src->vb_ip.addr.v4.s_addr,
sizeof(src->vb_ip.addr.v4.s_addr));
2597 dst->vb_ip.scope_id = 0;
2603 uint8_t *p = dst->vb_ip.addr.v6.s6_addr;
2605 if (src->vb_ip.prefix != 32) {
2607 "cast to IP address types",
2617 memcpy(p, (
uint8_t const *)&src->vb_ip.addr.v4.s_addr,
sizeof(src->vb_ip.addr.v4.s_addr));
2618 dst->vb_ip.scope_id = 0;
2623 if (src->vb_ip.prefix != 128) {
2624 fr_strerror_printf(
"Invalid cast from %s to %s. Only /128 (not /%i) prefixes may be "
2625 "cast to IP address types",
2634 memcpy(dst->vb_ip.addr.v6.s6_addr, src->vb_ip.addr.v6.s6_addr,
2635 sizeof(dst->vb_ip.addr.v6.s6_addr));
2636 dst->vb_ip.scope_id = src->vb_ip.scope_id;
2640 if (src->vb_length !=
sizeof(dst->vb_ip.addr.v6.s6_addr)) {
2641 fr_strerror_printf(
"Invalid cast from %s to %s. Needed octet string of length %zu, got %zu",
2644 sizeof(dst->vb_ip.addr.v6.s6_addr), src->vb_length);
2647 memcpy(&dst->vb_ip.addr.v6.s6_addr, src->vb_octets,
sizeof(dst->vb_ip.addr.v6.s6_addr));
2685 src->vb_strvalue, src->vb_length,
2686 NULL, src->tainted);
2698 dst->vb_ip.af = AF_INET6;
2703 uint8_t *p = dst->vb_ip.addr.v6.s6_addr;
2708 memcpy(p, (
uint8_t const *)&src->vb_ip.addr.v4.s_addr,
sizeof(src->vb_ip.addr.v4.s_addr));
2709 dst->vb_ip.prefix = 128;
2710 dst->vb_ip.scope_id = 0;
2716 uint8_t *p = dst->vb_ip.addr.v6.s6_addr;
2721 memcpy(p, (
uint8_t const *)&src->vb_ip.addr.v4.s_addr,
sizeof(src->vb_ip.addr.v4.s_addr));
2722 dst->vb_ip.prefix = (
sizeof(
v4_v6_map) << 3) + src->vb_ip.prefix;
2723 dst->vb_ip.scope_id = 0;
2728 dst->vb_ip.prefix = src->vb_ip.prefix;
2732 dst->vb_ip.prefix = 128;
2734 memcpy(dst->vb_ip.addr.v6.s6_addr, src->vb_ip.addr.v6.s6_addr,
2735 sizeof(dst->vb_ip.addr.v6.s6_addr));
2736 dst->vb_ip.scope_id = src->vb_ip.scope_id;
2740 if (src->vb_length != (
sizeof(dst->vb_ip.addr.v6.s6_addr) + 2)) {
2741 fr_strerror_printf(
"Invalid cast from %s to %s. Needed octet string of length %zu, got %zu",
2744 sizeof(dst->vb_ip.addr.v6.s6_addr) + 2, src->vb_length);
2747 dst->vb_ip.scope_id = src->vb_octets[0];
2748 dst->vb_ip.prefix = src->vb_octets[1];
2749 memcpy(&dst->vb_ip.addr.v6.s6_addr, src->vb_octets,
sizeof(dst->vb_ip.addr.v6.s6_addr));
2780 switch (src->type) {
2783 src->vb_strvalue, src->vb_length,
2784 NULL, src->tainted);
2798 switch (src->type) {
2807 if ((
array[0] != 0) || (
array[1] != 0))
return -1;
2809 memcpy(dst->vb_ether, &
array[2], 6);
2840 switch (src->type) {
2843 src->vb_strvalue, src->vb_length,
2844 NULL, src->tainted);
2861 switch (src->type) {
2863 dst->vb_bool = (src->vb_int8 != 0);
2867 dst->vb_bool = (src->vb_uint8 != 0);
2871 dst->vb_bool = (src->vb_int16 != 0);
2875 dst->vb_bool = (src->vb_uint16 != 0);
2879 dst->vb_bool = (src->vb_int32 != 0);
2883 dst->vb_bool = (src->vb_uint32 != 0);
2887 dst->vb_bool = (src->vb_int64 != 0);
2891 dst->vb_bool = (src->vb_uint64 != 0);
2895 dst->vb_bool = (src->vb_size != 0);
2903 dst->vb_bool = (fpclassify(src->vb_float32) == FP_ZERO);
2907 dst->vb_bool = (fpclassify(src->vb_float64) == FP_ZERO);
2931 #define SIGN_BIT_HIGH(_int, _len) ((((uint64_t)1) << (((_len) << 3) - 1)) & (_int))
2932 #define SIGN_PROMOTE(_int, _len) ((_len) < sizeof(_int) ? \
2933 (_int) | (~((__typeof__(_int))0)) << ((_len) << 3) : (_int))
2935 #if !defined(NDEBUG) || defined(STATIC_ANALYZER)
2941 "invalid source type len, expected > 0, got %zu",
2947 "Invalid cast from %s to %s. "
2948 "invalid source type len, expected <= %zu, got %zu",
2951 sizeof(uint64_t), len))
return -1;
2954 switch (src->type) {
2967 if (dst->enumv) res = dst->enumv->flags.flag_time_res;
2983 if (dst->enumv) res = dst->enumv->flags.flag_time_res;
2990 #ifdef WORDS_BIGENDIAN
2991 memcpy(((
uint8_t *)&tmp) + (
sizeof(tmp) - len),
3008 if ((int64_t)tmp <
min) {
3010 "outside value range %"PRId64
"-%"PRIu64,
3019 "outside value range 0-%"PRIu64,
3032 if (dst->enumv) res = dst->enumv->flags.flag_time_res;
3046 if (dst->enumv) res = dst->enumv->flags.flag_time_res;
3057 #ifdef WORDS_BIGENDIAN
3082 switch (src->type) {
3085 src->vb_strvalue, src->vb_length,
3086 NULL, src->tainted);
3112 memcpy(&tmp.vb_uint32, &src->vb_ip.addr.v4,
sizeof(tmp.vb_uint32));
3133 memcpy(((
uint8_t *)&tmp.vb_uint64) + (
sizeof(tmp.vb_uint64) -
sizeof(src->vb_ether)),
3134 &src->vb_ether,
sizeof(src->vb_ether));
3135 #ifndef WORDS_BIGENDIAN
3185 switch (src->type) {
3188 num = (double) src->vb_float32;
3196 num = src->vb_float64;
3211 num = src->vb_int16;
3215 num = src->vb_int32;
3219 num = src->vb_int64;
3223 num = src->vb_uint8;
3227 num = src->vb_uint16;
3231 num = src->vb_uint32;
3235 num = src->vb_uint64;
3264 dst->vb_float32 = num;
3266 dst->vb_float64 = num;
3331 if (dst_type == src->type) {
3335 if (ret < 0)
return ret;
3337 dst->enumv = dst_enumv;
3392 dst->type = dst_type;
3393 dst->enumv = dst_enumv;
3409 if (when > INT64_MAX) {
3414 dst->type = dst_type;
3415 dst->enumv = dst_enumv;
3457 src->vb_strvalue, src->vb_length,
3458 NULL, src->tainted);
3464 fr_strerror_printf(
"Invalid cast from %s to %s. Source is length %zd is smaller than "
3465 "destination type size %zd",
3475 "destination type size %zd",
3490 tmp.type = dst_type;
3491 dst->enumv = dst_enumv;
3499 dst->type = dst_type;
3500 dst->enumv = dst_enumv;
3528 fr_value_box_entry_t entry = vb->entry;
3534 if (vb->type == dst_type) {
3535 vb->enumv = dst_enumv;
3583 switch (ipaddr->
af) {
3598 memcpy(&dst->vb_ip, ipaddr,
sizeof(dst->vb_ip));
3619 memcpy(dst, &src->vb_ip,
sizeof(*dst));
3632 switch (
data->type) {
3649 while ((vb = fr_value_box_list_next(&
data->vb_group, vb))) {
3663 memset(&
data->datum, 0,
sizeof(
data->datum));
3691 switch (src->type) {
3713 dst->vb_strvalue = str;
3722 if (src->vb_length) {
3723 bin = talloc_memdup(ctx, src->vb_octets, src->vb_length);
3728 talloc_set_type(bin,
uint8_t);
3730 bin = talloc_array(ctx,
uint8_t, 0);
3732 dst->vb_octets = bin;
3743 while ((child = fr_value_box_list_next(&src->vb_group, child))) {
3753 fr_value_box_list_talloc_free(&dst->vb_group);
3763 fr_value_box_list_insert_tail(&dst->vb_group,
new);
3785 switch (src->type) {
3792 dst->datum.ptr = ctx ? talloc_reference(ctx, src->datum.ptr) : src->datum.ptr;
3811 switch (src->type) {
3819 str = talloc_steal(ctx, src->vb_strvalue);
3824 talloc_set_type(str,
char);
3825 dst->vb_strvalue = str;
3827 memset(&src->datum, 0,
sizeof(src->datum));
3835 bin = talloc_steal(ctx, src->vb_octets);
3840 talloc_set_type(bin,
uint8_t);
3842 dst->vb_octets = bin;
3844 memset(&src->datum, 0,
sizeof(src->datum));
3852 while ((child = fr_value_box_list_pop_head(&src->vb_group))) {
3853 child = talloc_steal(ctx, child);
3858 fr_value_box_list_insert_tail(&dst->vb_group, child);
3877 char const *src,
bool tainted)
3888 dst->vb_strvalue = str;
3889 dst->vb_length = talloc_array_length(str) - 1;
3909 len = strlen(vb->vb_strvalue);
3910 str = talloc_realloc(ctx,
UNCONST(
char *, vb->vb_strvalue),
char, len + 1);
3915 vb->vb_length = len;
3933 char const *
fmt, va_list ap)
3942 if (!str)
return -1;
3945 dst->vb_strvalue = str;
3946 dst->vb_length = talloc_array_length(str) - 1;
3964 char const *
fmt, ...)
3986 char const *src,
bool tainted)
3989 dst->vb_strvalue = src;
3990 dst->vb_length = strlen(src);
4004 vb->vb_strvalue = src;
4005 vb->vb_length = len < 0 ? strlen(src) : (
size_t)len;
4021 size_t len,
bool tainted)
4025 str = talloc_zero_array(ctx,
char, len + 1);
4033 dst->vb_strvalue = str;
4034 dst->vb_length = talloc_array_length(str) - 1;
4061 memcpy(&cstr, &dst->vb_strvalue,
sizeof(cstr));
4063 clen = talloc_array_length(dst->vb_strvalue) - 1;
4064 if (clen == len)
return 0;
4066 str = talloc_realloc(ctx, cstr,
char, len + 1);
4076 memset(str + clen,
'\0', (len - clen) + 1);
4080 dst->vb_strvalue = str;
4081 dst->vb_length = len;
4098 char const *src,
size_t len,
bool tainted)
4115 dst->vb_strvalue = str;
4116 dst->vb_length = len;
4126 str = talloc_array(ctx,
char, len + 1);
4136 dst->vb_strvalue = str;
4137 dst->vb_length = len;
4158 char const *src,
bool tainted)
4164 len = talloc_array_length(src);
4165 if ((len == 0) || (src[len - 1] !=
'\0')) {
4182 char const *src,
size_t len,
bool tainted)
4185 dst->vb_strvalue = src;
4186 dst->vb_length = len;
4203 char const *src,
bool tainted)
4209 len = talloc_array_length(src);
4210 if ((len == 0) || (src[len - 1] !=
'\0')) {
4216 dst->vb_strvalue = ctx ? talloc_reference(ctx, src) : src;
4217 dst->vb_length = len - 1;
4238 if (len == 0)
return 0;
4247 ptr = dst->datum.ptr;
4250 if (talloc_reference_count(ptr) > 0) {
4255 nlen = dst->vb_length + len + 1;
4256 nptr = talloc_realloc(ctx, ptr,
char, dst->vb_length + len + 1);
4259 __FUNCTION__, talloc_get_name(ptr), talloc_array_length(ptr), nlen);
4262 talloc_set_type(nptr,
char);
4265 memcpy(ptr + dst->vb_length, src, len);
4267 dst->tainted = dst->tainted || tainted;
4268 dst->datum.ptr = ptr;
4269 dst->vb_length += len;
4271 ptr[dst->vb_length] =
'\0';
4292 len = talloc_array_length(src);
4293 if ((len == 0) || (src[len - 1] !=
'\0')) {
4321 size_t len,
bool tainted)
4325 bin = talloc_array(ctx,
uint8_t, len);
4330 talloc_set_type(bin,
uint8_t);
4333 dst->vb_octets = bin;
4334 dst->vb_length = len;
4361 memcpy(&cbin, &dst->vb_octets,
sizeof(cbin));
4363 clen = talloc_array_length(dst->vb_octets);
4364 if (clen == len)
return 0;
4372 bin = talloc_realloc(ctx, cbin,
uint8_t, len);
4374 bin = talloc_array(ctx,
uint8_t, 0);
4390 if (clen < len) memset(bin + clen, 0x00, len - clen);
4391 dst->vb_octets = bin;
4392 dst->vb_length = len;
4418 uint8_t const *src,
size_t len,
bool tainted)
4428 bin = talloc_memdup(ctx, src, len);
4433 talloc_set_type(bin,
uint8_t);
4436 dst->vb_octets = bin;
4437 dst->vb_length = len;
4447 bin = talloc_size(ctx, len);
4453 talloc_set_type(bin,
uint8_t);
4456 dst->vb_octets = bin;
4457 dst->vb_length = len;
4476 uint8_t const *src,
bool tainted)
4498 uint8_t const *src,
size_t len,
bool tainted)
4501 dst->vb_octets = src;
4502 dst->vb_length = len;
4516 uint8_t const *src,
bool tainted)
4521 dst->vb_octets = ctx ? talloc_reference(ctx, src) : src;
4522 dst->vb_length = talloc_array_length(src);
4541 if (len == 0)
return 0;
4552 if (talloc_reference_count(dst->datum.ptr) > 0) {
4557 nlen = dst->vb_length + len;
4558 nptr = talloc_realloc(ctx, dst->datum.ptr,
uint8_t, dst->vb_length + len);
4562 talloc_get_name(dst->datum.ptr),
4563 talloc_array_length((
uint8_t const *)dst->datum.ptr), nlen);
4567 memcpy(nptr + dst->vb_length, src, len);
4569 dst->tainted = dst->tainted || tainted;
4570 dst->datum.ptr = nptr;
4571 dst->vb_length += len;
4601 vb->vb_uint8 = vb->vb_uint8 ==
UINT8_MAX ? 0 : vb->vb_uint8 + 1;
4605 vb->vb_uint16 = vb->vb_uint16 == UINT16_MAX ? 0 : vb->vb_uint16 + 1;
4609 vb->vb_uint32 = vb->vb_uint32 == UINT32_MAX ? 0 : vb->vb_uint32 + 1;
4613 vb->vb_uint64 = vb->vb_uint64 == UINT64_MAX ? 0 : vb->vb_uint64 + 1;
4617 vb->vb_int8 = vb->vb_int8 == INT8_MAX ? INT8_MIN : vb->vb_int8 + 1;
4621 vb->vb_int16 = vb->vb_int16 == INT16_MAX ? INT16_MIN : vb->vb_int16 + 1;
4625 vb->vb_int32 = vb->vb_int32 == INT32_MAX ? INT32_MIN : vb->vb_int32 + 1;
4629 vb->vb_int64 = vb->vb_int64 == INT64_MAX ? INT64_MIN : vb->vb_int64 + 1;
4649 static inline CC_HINT(always_inline)
4652 fr_sbuff_t *
in, fr_sbuff_parse_rules_t const *rules,
bool tainted)
4718 rules->escapes ? rules->escapes->chr :
'\0');
4730 fr_sbuff_parse_error_to_strerror(
err);
4753 fr_sbuff_t *
in, fr_sbuff_parse_rules_t
const *rules,
bool tainted)
4755 static fr_sbuff_parse_rules_t default_rules;
4762 if (!rules) rules = &default_rules;
4769 if (dst_enumv && dst_enumv->flags.has_value) {
4786 rules->terminals, rules->escapes);
4788 fr_sbuff_set_to_start(&our_in);
4794 fr_sbuff_set_to_start(&our_in);
4816 if (!dst_enumv || !unescaped) {
4819 if (
unlikely(fr_sbuff_out_aunescape_until(ctx, &
buff, &our_in, SIZE_MAX,
4820 rules->terminals, rules->escapes) < 0)) {
4846 if (!dst_enumv || !unescaped) {
4851 fr_sbuff_out_aunescape_until(ctx, &
buff, &our_in, SIZE_MAX,
4852 rules->terminals, rules->escapes);
4854 if (talloc_array_length(
buff) == 1) {
4859 bin = talloc_realloc(ctx,
buff,
uint8_t, talloc_array_length(
buff) - 1);
4865 talloc_set_type(bin,
uint8_t);
4876 bin = talloc_zero_array(ctx,
uint8_t, 0);
4891 fr_sbuff_marker(&hex_start, &our_in);
4908 if ((hex_len & 0x01) != 0) {
4934 if (!name_len)
return 0;
4946 "for non-prefix types", addr.
prefix);
4950 memcpy(&dst->vb_ip, &addr,
sizeof(dst->vb_ip));
4957 if (!name_len)
return 0;
4967 if (!name_len)
return 0;
4983 if (addr.
prefix != 128) {
4986 "for non-prefix types", addr.
prefix);
4990 memcpy(&dst->vb_ip, &addr,
sizeof(dst->vb_ip));
4997 if (!name_len)
return 0;
5007 if (!name_len)
return 0;
5019 if ((addr.
af == AF_INET) && (addr.
prefix != 32)) {
5020 goto fail_ipv4_prefix;
5023 if ((addr.
af == AF_INET6) && (addr.
prefix != 128)) {
5024 goto fail_ipv6_prefix;
5027 memcpy(&dst->vb_ip, &addr,
sizeof(dst->vb_ip));
5034 if (!name_len)
return 0;
5064 if (slen >= 0)
return slen;
5070 if (!rules->escapes) {
5076 dst->vb_bool = (stmp != 0);
5082 dst->vb_bool = (
utmp != 0);
5088 "\"yes\", \"no\", \"true\", \"false\" or any unquoted integer");
5128 fr_sbuff_set_to_start(&our_in);
5133 fr_sbuff_parse_error_to_strerror(
err);
5176 false, rules->terminals);
5177 if (slen < 0)
return slen;
5199 if (rules && rules->terminals) {
5203 rules->terminals, rules->escapes);
5204 if (len >=
sizeof(
buffer))
goto too_small;
5235 dst->enumv = dst_enumv;
5252 dst->type = dst_type;
5253 dst->tainted = tainted;
5258 dst->enumv = dst_enumv;
5259 fr_value_box_list_entry_init(dst);
5270 fr_sbuff_parse_rules_t prules = { .escapes = erules };
5273 if (slen <= 0)
return slen;
5276 fr_strerror_printf(
"Failed parsing '%s'. %zu bytes of trailing data after string value \"%pV\"",
5280 return (slen -
inlen) - 1;
5307 if (
data->enumv &&
data->enumv->flags.has_value) {
5317 switch (
data->type) {
5320 data->vb_strvalue,
data->vb_length, e_rules);
5357 data->vb_ether[0],
data->vb_ether[1],
5358 data->vb_ether[2],
data->vb_ether[3],
5359 data->vb_ether[4],
data->vb_ether[5]);
5410 if (
data->enumv) res =
data->enumv->flags.flag_time_res;
5423 bool is_unsigned =
false;
5426 res =
data->enumv->flags.flag_time_res;
5427 is_unsigned =
data->enumv->flags.is_unsigned;
5443 if (!e_rules || (!e_rules->do_oct && !e_rules->do_hex)) {
5454 NULL, NULL, &our_out,
UNCONST(fr_value_box_list_t *, &
data->vb_group),
5455 ", ", (
sizeof(
", ") - 1), e_rules,
5495 switch (
data->type) {
5539 if (fr_value_box_list_empty(list))
return 0;
5544 if (!flatten)
goto print;
5546 sep, sep_len, e_rules,
5547 proc_action, flatten);
5555 if (e_rules && (vb->tainted || e_rules->do_oct || e_rules->do_hex)) {
5556 slen =
fr_sbuff_in_escape(&our_sbuff, (
char const *)vb->vb_strvalue, vb->vb_length, e_rules);
5563 if (vb->tainted && e_rules)
goto print;
5581 if (sep && fr_value_box_list_next(list, vb)) {
5583 if (slen < 0)
goto error;
5593 if (tainted && vb->tainted) *tainted =
true;
5626 uint8_t const *sep,
size_t sep_len,
5630 TALLOC_CTX *tmp_ctx = NULL;
5633 if (fr_value_box_list_empty(list))
return 0;
5638 if (!flatten)
goto cast;
5641 proc_action, flatten);
5660 if (!tmp_ctx) tmp_ctx = talloc_pool(NULL, 1024);
5681 if (sep && fr_value_box_list_next(list, vb)) {
5683 if (slen < 0)
goto error;
5695 if (tainted && vb->tainted) *tainted =
true;
5731 fr_dbuff_uctx_talloc_t dbuff_tctx;
5737 bool tainted =
false;
5740 fr_value_box_entry_t entry;
5742 if (fr_value_box_list_empty(list)) {
5749 if (
unlikely(!fr_sbuff_init_talloc(ctx, &sbuff, &sbuff_tctx, 256, max_size)))
return -1;
5771 if (
out == head_vb) {
5809 proc_action, flatten) < 0) {
5810 fr_value_box_list_insert_head(list, head_vb);
5825 proc_action, flatten) < 0) {
5826 fr_value_box_list_insert_head(list, head_vb);
5837 fr_value_box_list_insert_head(list,
out);
5851 proc_action, flatten) < 0)
goto error;
5862 proc_action, flatten) < 0)
goto error;
5906 ret = escape(vb, uctx);
5909 vb->safe_for = safe_for;
5957 fr_value_box_list_remove(&child->vb_group, grandchild);
5958 if (steal) talloc_steal(ctx, grandchild);
5959 fr_value_box_list_insert_before(list, child, grandchild);
5980 char *aggr, *td = NULL;
5981 TALLOC_CTX *pool = NULL;
5983 if (!vb)
return NULL;
5986 if (!aggr)
return NULL;
5987 if (!fr_value_box_list_next(list, vb))
return aggr;
5993 pool = talloc_pool(NULL, 255);
5996 while ((vb = fr_value_box_list_next(list, vb))) {
5997 char *str, *new_aggr;
6030 char *aggr, *td = NULL;
6031 TALLOC_CTX *pool = NULL;
6033 if (!vb)
return NULL;
6040 if (!aggr)
return NULL;
6041 if (!fr_value_box_list_next(list, vb))
return aggr;
6047 pool = talloc_pool(NULL, 255);
6050 while ((vb = fr_value_box_list_next(list, vb))) {
6051 char *str, *new_aggr;
6085 return fr_hash(vb->vb_strvalue, vb->vb_length);
6088 return fr_hash(vb->vb_octets, vb->vb_length);
6110 while ((in_p = fr_value_box_list_next(
in, in_p))) {
6116 fr_value_box_list_talloc_free(
out);
6138 while ((vb = fr_value_box_list_next(
head, vb))) {
6140 if (vb->tainted)
return true;
6154 while ((vb = fr_value_box_list_next(
head, vb))) {
6168 while ((vb = fr_value_box_list_next(
head, vb))) {
6170 vb->tainted =
false;
6196 fr_fatal_assert_msg(vb->vb_strvalue,
"CONSISTENCY CHECK FAILED %s[%i]: fr_value_box_t strvalue field "
6199 "CONSISTENCY CHECK FAILED %s[%i]: fr_value_box_t strvalue field "
6200 "not null terminated",
file,
line);
6202 size_t len = talloc_array_length(vb->vb_strvalue);
6206 fr_fatal_assert_fail(
"CONSISTENCY CHECK FAILED %s[%u]: Expected fr_value_box_t->vb_strvalue talloc buffer "
6207 "len >= %zu, got %zu",
6208 file,
line, vb->vb_length + 1, len);
6214 fr_fatal_assert_msg(vb->vb_octets,
"CONSISTENCY CHECK FAILED %s[%i]: fr_value_box_t octets field "
6219 fr_fatal_assert_msg(vb->vb_void,
"CONSISTENCY CHECK FAILED %s[%i]: fr_value_box_t ptr field "
6242 vb->safe_for = safe_for;
6284 return (fr_value_box_list_num_elements(&
in->vb_group) > 0);
6291 return (
in->vb_length > 0);
6308 #define INFO_INDENT(_fmt, ...) FR_FAULT_LOG("%*s"_fmt, depth * 2, " ", ## __VA_ARGS__)
static int const char char buffer[256]
static int const char * fmt
#define fr_base16_encode(_out, _in)
#define fr_base16_decode(_err, _out, _in, _no_trailing)
#define UNCONST(_type, _ptr)
Remove const qualification from a pointer.
#define L(_str)
Helper for initialising arrays of string literals.
#define FALL_THROUGH
clang 10 doesn't recognised the FALL-THROUGH comment anymore
#define static_assert
For systems with an old version libc, define static_assert.
#define SIZEOF_MEMBER(_t, _m)
#define CMP(_a, _b)
Same as CMP_PREFER_SMALLER use when you don't really care about ordering, you just want an ordering.
static fr_atomic_queue_t * aq
int fr_dbuff_trim_talloc(fr_dbuff_t *dbuff, size_t len)
Trim a talloced dbuff to the minimum length required to represent the contained string.
#define fr_dbuff_used(_dbuff_or_marker)
Return the number of bytes remaining between the start of the dbuff or marker and the current positio...
#define FR_DBUFF_OUT_UINT64V_RETURN(_num, _dbuff_or_marker, _len)
Read bytes from a dbuff or marker and interpret them as a network order unsigned integer.
#define fr_dbuff_init(_out, _start, _len_or_end)
Initialise an dbuff for encoding or decoding.
#define fr_dbuff_start(_dbuff_or_marker)
Return the 'start' position of a dbuff or marker.
#define FR_DBUFF_OUT_INT64V_RETURN(_num, _dbuff_or_marker, _len)
Read bytes from a dbuff or marker and interpret them as a network order unsigned integer.
#define fr_dbuff_buff(_dbuff_or_marker)
Return the underlying buffer in a dbuff or one of marker.
#define fr_dbuff_out_memcpy(_out, _dbuff_or_marker, _outlen)
Copy exactly _outlen bytes from the dbuff.
#define FR_DBUFF_MEMSET_RETURN(_dbuff_or_marker, _c, _inlen)
Set _inlen bytes of a dbuff or marker to _c returning if there is insufficient space.
#define FR_DBUFF_OUT_MEMCPY_RETURN(_out, _dbuff_or_marker, _outlen)
Copy outlen bytes from the dbuff returning if there's insufficient data in the dbuff.
#define FR_DBUFF_IN_MEMCPY_RETURN(_dbuff_or_marker, _in, _inlen)
Copy exactly _inlen bytes into dbuff or marker returning if there's insufficient space.
#define fr_dbuff_in_memcpy(_dbuff_or_marker, _in, _inlen)
Copy exactly _inlen bytes into a dbuff or marker.
#define FR_DBUFF_IN_RETURN(_dbuff_or_marker, _in)
Copy data from a fixed sized C type into a dbuff returning if there is insufficient space.
static fr_dbuff_t * fr_dbuff_init_talloc(TALLOC_CTX *ctx, fr_dbuff_t *dbuff, fr_dbuff_uctx_talloc_t *tctx, size_t init, size_t max)
Initialise a special dbuff which automatically extends as additional data is written.
#define FR_DBUFF(_dbuff_or_marker)
Create a new dbuff pointing to the same underlying buffer.
#define FR_DBUFF_OUT_RETURN(_out, _dbuff_or_marker)
Copy data from a dbuff or marker to a fixed sized C type returning if there is insufficient data.
#define FR_DBUFF_IN_BYTES_RETURN(_dbuff_or_marker,...)
Copy a byte sequence into a dbuff or marker returning if there's insufficient space.
#define FR_DBUFF_TMP(_start, _len_or_end)
Creates a compound literal to pass into functions which accept a dbuff.
#define fr_fatal_assert_fail(_msg,...)
Calls panic_action ifndef NDEBUG, else logs error and causes the server to exit immediately with code...
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
#define fr_assert_fail(_msg,...)
Calls panic_action ifndef NDEBUG, else logs error.
#define fr_cond_assert_msg(_x, _fmt,...)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
#define fr_fatal_assert_msg(_x, _fmt,...)
Calls panic_action ifndef NDEBUG, else logs error and causes the server to exit immediately with code...
@ FLAG_LENGTH_UINT8
string / octets type is prefixed by uint8 of length
@ FLAG_LENGTH_UINT16
string / octets type is prefixed by uint16 of length
struct value_box_s fr_value_box_t
fr_value_box_t const * value
Enum value (what name maps to).
#define da_is_length_field(_da)
fr_dict_enum_value_t * fr_dict_enum_by_name(fr_dict_attr_t const *da, char const *name, ssize_t len)
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.
Value of an enumerated attribute.
static int fr_dlist_insert_tail(fr_dlist_head_t *list_head, void *ptr)
Insert an item into the tail of a list.
uint32_t fr_hash(void const *data, size_t size)
char * fr_inet_ifid_ntop(char *out, size_t outlen, uint8_t const *ifid)
Print an interface-id in standard colon notation.
int fr_ipaddr_is_prefix(fr_ipaddr_t const *ipaddr)
Determine if an address is a prefix.
uint8_t * fr_inet_ifid_pton(uint8_t out[static 8], char const *ifid_str)
Convert interface-id in colon notation to 8 byte binary form.
int fr_inet_pton6(fr_ipaddr_t *out, char const *value, ssize_t inlen, bool resolve, bool fallback, bool mask)
Parse an IPv6 address or IPv6 prefix in presentation format (and others)
char * fr_inet_ntop_prefix(char out[static FR_IPADDR_PREFIX_STRLEN], size_t outlen, fr_ipaddr_t const *addr)
Print a fr_ipaddr_t as a CIDR style network prefix.
bool fr_hostname_lookups
hostname -> IP lookups?
int fr_inet_pton(fr_ipaddr_t *out, char const *value, ssize_t inlen, int af, bool resolve, bool mask)
Simple wrapper to decide whether an IP value is v4 or v6 and call the appropriate parser.
int fr_ipaddr_is_inaddr_any(fr_ipaddr_t const *ipaddr)
Determine if an address is the INADDR_ANY address for its address family.
int8_t fr_ipaddr_cmp(fr_ipaddr_t const *a, fr_ipaddr_t const *b)
Compare two ip addresses.
char * fr_inet_ntop(char out[static FR_IPADDR_STRLEN], size_t outlen, fr_ipaddr_t const *addr)
Print the address portion of a fr_ipaddr_t.
uint8_t prefix
Prefix length - Between 0-32 for IPv4 and 0-128 for IPv6.
uint8_t addr[6]
Ethernet address.
Struct to represent an ethernet address.
#define fr_multiply(_out, _a, _b)
Multiplies two integers together.
static const uint8_t * zero
size_t fr_sbuff_out_unescape_until(fr_sbuff_t *out, fr_sbuff_t *in, size_t len, fr_sbuff_term_t const *tt, fr_sbuff_unescape_rules_t const *u_rules)
@ FR_TYPE_TIME_DELTA
A period of time measured in nanoseconds.
@ FR_TYPE_FLOAT32
Single precision floating point.
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
@ FR_TYPE_INT8
8 Bit signed integer.
@ FR_TYPE_TLV
Contains nested attributes.
@ FR_TYPE_ETHERNET
48 Bit Mac-Address.
@ FR_TYPE_IPV6_PREFIX
IPv6 Prefix.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_MAX
Number of defined data types.
@ FR_TYPE_NULL
Invalid (uninitialised) attribute type.
@ 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_VALUE_BOX
A boxed value.
@ FR_TYPE_UINT8
8 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_STRUCT
like TLV, but without T or L, and fixed-width children
@ FR_TYPE_INT32
32 Bit signed integer.
@ FR_TYPE_VENDOR
Attribute that represents a vendor in the attribute tree.
@ 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_SIZE
Unsigned integer capable of representing any memory address on the local system.
@ FR_TYPE_VSA
Vendor-Specific, for RADIUS attribute 26.
@ FR_TYPE_COMBO_IP_ADDR
IPv4 or IPv6 address depending on length.
@ FR_TYPE_IFID
Interface ID.
@ FR_TYPE_OCTETS
Raw octets.
@ FR_TYPE_GROUP
A grouping of other attributes.
@ FR_TYPE_FLOAT64
Double precision floating point.
int fr_inet_pton4(fr_ipaddr_t *out, char const *value, ssize_t inlen, bool resolve, bool fallback, bool mask_bits)
@ FR_SBUFF_PARSE_ERROR_NOT_FOUND
String does not contain a token matching the output type.
@ FR_SBUFF_PARSE_OK
No error.
static size_t array[MY_ARRAY_SIZE]
static uint8_t depth(fr_minmax_heap_index_t i)
void * memset_explicit(void *ptr, int ch, size_t len)
static uint64_t fr_nbo_to_uint64(uint8_t const data[static sizeof(uint64_t)])
Read an unsigned 64bit integer from wire format (big endian)
static void fr_nbo_from_uint64(uint8_t out[static sizeof(uint64_t)], uint64_t num)
Write out an unsigned 64bit integer in wire format (big endian)
char * fr_vasprintf(TALLOC_CTX *ctx, char const *fmt, va_list ap)
int fr_sbuff_trim_talloc(fr_sbuff_t *sbuff, size_t len)
Trim a talloced sbuff to the minimum length required to represent the contained string.
size_t fr_sbuff_adv_past_allowed(fr_sbuff_t *sbuff, size_t len, bool const allowed[static UINT8_MAX+1], fr_sbuff_term_t const *tt)
Wind position past characters in the allowed set.
ssize_t fr_sbuff_in_escape(fr_sbuff_t *sbuff, char const *in, size_t inlen, fr_sbuff_escape_rules_t const *e_rules)
Print an escaped string to an sbuff.
bool const sbuff_char_class_hex[UINT8_MAX+1]
bool const sbuff_char_class_uint[UINT8_MAX+1]
static size_t min(size_t x, size_t y)
bool const sbuff_char_class_hostname[UINT8_MAX+1]
bool fr_sbuff_is_terminal(fr_sbuff_t *in, fr_sbuff_term_t const *tt)
Efficient terminal string search.
ssize_t fr_sbuff_in_bstrncpy(fr_sbuff_t *sbuff, char const *str, size_t len)
Copy bytes into the sbuff up to the first \0.
size_t fr_sbuff_adv_until(fr_sbuff_t *sbuff, size_t len, fr_sbuff_term_t const *tt, char escape_chr)
Wind position until we hit a character in the terminal set.
size_t fr_sbuff_out_bstrncpy(fr_sbuff_t *out, fr_sbuff_t *in, size_t len)
Copy as many bytes as possible from a sbuff to a sbuff.
bool fr_sbuff_next_if_char(fr_sbuff_t *sbuff, char c)
Return true if the current char matches, and if it does, advance.
#define fr_sbuff_start(_sbuff_or_marker)
#define fr_sbuff_adv_past_str_literal(_sbuff, _needle)
#define FR_SBUFF_IN_CHAR_RETURN(_sbuff,...)
#define fr_sbuff_set(_dst, _src)
#define FR_SBUFF_IN(_start, _len_or_end)
#define fr_sbuff_adv_past_strcase_literal(_sbuff, _needle)
#define fr_sbuff_current(_sbuff_or_marker)
#define FR_SBUFF_IN_ESCAPE_BUFFER_RETURN(...)
#define FR_SBUFF_TERMS(...)
Initialise a terminal structure with a list of sorted strings.
char const * name
Name for rule set to aid we debugging.
#define FR_SBUFF_IN_STRCPY_LITERAL_RETURN(_sbuff, _str)
#define fr_sbuff_extend(_sbuff_or_marker)
#define fr_sbuff_buff(_sbuff_or_marker)
#define FR_SBUFF_RETURN(_func, _sbuff,...)
#define FR_SBUFF_ERROR_RETURN(_sbuff_or_marker)
#define FR_SBUFF_IN_SPRINTF_RETURN(...)
#define SBUFF_CHAR_UNPRINTABLES_EXTENDED
#define FR_SBUFF(_sbuff_or_marker)
#define fr_sbuff_out(_err, _out, _in)
#define FR_SBUFF_IN_ESCAPE_RETURN(...)
#define fr_sbuff_remaining(_sbuff_or_marker)
#define FR_SBUFF_OUT(_start, _len_or_end)
#define SBUFF_CHAR_UNPRINTABLES_LOW
#define fr_sbuff_used(_sbuff_or_marker)
#define FR_SBUFF_TERM(_str)
Initialise a terminal structure with a single string.
#define FR_SBUFF_IN_STRCPY_RETURN(...)
#define FR_SBUFF_TALLOC_THREAD_LOCAL(_out, _init, _max)
Talloc sbuff extension structure.
Set of parsing rules for *unescape_until functions.
fr_slen_t fr_size_from_str(size_t *out, fr_sbuff_t *in)
Parse a size string with optional unit.
fr_slen_t fr_size_to_str(fr_sbuff_t *out, size_t in)
Print a size string with unit.
static char buff[sizeof("18446744073709551615")+3]
PRIVATE void float64(struct DATA *p, double d)
fr_aka_sim_id_type_t type
char * talloc_typed_strdup(TALLOC_CTX *ctx, char const *p)
Call talloc_strdup, setting the type on the new chunk correctly.
char * talloc_buffer_append_variadic_buffer(TALLOC_CTX *ctx, char *to, int argc,...)
Concatenate to + ...
char * talloc_bstrndup(TALLOC_CTX *ctx, char const *in, size_t inlen)
Binary safe strndup function.
#define talloc_get_type_abort_const
fr_slen_t fr_time_delta_from_substr(fr_time_delta_t *out, fr_sbuff_t *in, fr_time_res_t hint, bool no_trailing, fr_sbuff_term_t const *tt)
Create fr_time_delta_t from a string.
int fr_unix_time_from_str(fr_unix_time_t *date, char const *date_str, fr_time_res_t hint)
Convert string in various formats to a fr_unix_time_t.
int64_t fr_time_scale(int64_t t, fr_time_res_t hint)
Scale an input time to NSEC, clamping it at max / min.
fr_slen_t fr_unix_time_to_str(fr_sbuff_t *out, fr_unix_time_t time, fr_time_res_t res)
Convert unix time to string.
fr_slen_t fr_time_delta_to_str(fr_sbuff_t *out, fr_time_delta_t delta, fr_time_res_t res, bool is_unsigned)
Print fr_time_delta_t to a string with an appropriate suffix.
int64_t const fr_time_multiplier_by_res[]
static fr_time_delta_t fr_time_delta_from_integer(bool *overflow, int64_t integer, fr_time_res_t res)
static int64_t fr_time_delta_to_integer(fr_time_delta_t delta, fr_time_res_t res)
static int64_t fr_time_delta_unwrap(fr_time_delta_t time)
static int8_t fr_time_delta_cmp(fr_time_delta_t a, fr_time_delta_t b)
Compare two fr_time_delta_t values.
#define fr_time_delta_isneg(_a)
#define fr_time_delta_wrap(_time)
#define fr_unix_time_wrap(_time)
fr_time_res_t
The base resolution for print parse operations.
static fr_unix_time_t fr_unix_time_from_integer(bool *overflow, int64_t integer, fr_time_res_t res)
static int8_t fr_unix_time_cmp(fr_unix_time_t a, fr_unix_time_t b)
Compare two fr_unix_time_t values.
static uint64_t fr_unix_time_unwrap(fr_unix_time_t time)
static int64_t fr_unix_time_to_integer(fr_unix_time_t delta, fr_time_res_t res)
const char fr_token_quote[T_TOKEN_LAST]
Convert tokens back to a quoting character.
@ T_SOLIDUS_QUOTED_STRING
void fr_strerror_clear(void)
Clears all pending messages from the talloc pools.
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
#define fr_strerror_const(_msg)
#define FR_TYPE_VARIABLE_SIZE
#define FR_TYPE_STRUCTURAL_EXCEPT_GROUP
#define fr_type_is_non_leaf(_x)
static char const * fr_type_to_str(fr_type_t type)
Return a static string containing the type name.
#define fr_type_is_group(_x)
#define fr_type_is_variable_size(_x)
#define fr_type_is_structural(_x)
#define fr_type_is_fixed_size(_x)
#define FR_TYPE_STRUCTURAL
#define fr_type_is_ip(_x)
#define FR_TYPE_INTEGER_EXCEPT_BOOL
#define fr_type_is_leaf(_x)
#define FR_TYPE_FIXED_SIZE
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)
void fr_value_box_list_verify(char const *file, int line, fr_value_box_list_t const *list)
static void _fr_value_box_list_debug(fr_value_box_list_t const *head, int depth)
static void _fr_value_box_debug(fr_value_box_t const *vb, int depth, int idx)
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.
size_t const fr_value_box_field_sizes[]
How many bytes wide each of the value data fields are.
fr_sbuff_escape_rules_t fr_value_escape_double
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.
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)
Print a formatted string using our internal printf wrapper and assign it to a value box.
ssize_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, bool tainted)
Convert string value to a fr_value_box_t type.
void fr_value_box_debug(fr_value_box_t const *vb)
Print the value of a box as info messages.
#define INFO_INDENT(_fmt,...)
int fr_value_box_bstrn_append(TALLOC_CTX *ctx, fr_value_box_t *dst, char const *src, size_t len, bool tainted)
Append bytes from a buffer to an existing fr_value_box_t.
void fr_value_box_mark_unsafe(fr_value_box_t *vb)
Mark a value-box as "unsafe".
fr_sbuff_escape_rules_t fr_value_escape_single
ssize_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, bool tainted)
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.
uint32_t fr_value_box_hash(fr_value_box_t const *vb)
Hash the contents of a value box.
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.
static fr_slen_t fr_value_box_from_numeric_substr(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, bool tainted)
Convert integer encoded as string to a fr_value_box_t type.
static int fr_value_box_cast_to_strvalue(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 any supported type to a string.
int fr_value_box_mem_append_buffer(TALLOC_CTX *ctx, fr_value_box_t *dst, uint8_t const *src, bool tainted)
Append a talloc buffer to an existing fr_value_box_t.
fr_sbuff_parse_rules_t const value_parse_rules_double_unquoted
fr_sbuff_parse_rules_t const value_parse_rules_solidus_quoted
ssize_t fr_value_box_list_concat_as_octets(bool *tainted, bool *secret, 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.
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.
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.
int fr_value_box_list_escape_in_place(fr_value_box_list_t *list, fr_value_box_escape_t escape, fr_value_box_safe_for_t safe_for, void *uctx)
Escape a list of value boxes in place.
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.
#define network_min_size(_x)
Sanity checks.
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_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.
int fr_value_box_asprintf(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, bool tainted, char const *fmt,...)
Print a formatted string using our internal printf wrapper and assign it to a value box.
fr_sbuff_parse_rules_t const * value_parse_rules_unquoted_char[UINT8_MAX]
fr_sbuff_parse_rules_t const * value_parse_rules_quoted[T_TOKEN_LAST]
Parse rules for quoted strings.
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.
static size_t const fr_value_box_network_sizes[FR_TYPE_MAX+1][2]
static int fr_value_box_cast_to_float(UNUSED 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 any value to a floating point value.
int8_t fr_value_box_cmp(fr_value_box_t const *a, fr_value_box_t const *b)
Compare two values.
#define SIGN_BIT_HIGH(_int, _len)
size_t const fr_value_box_offsets[]
Where the value starts in the fr_value_box_t.
fr_sbuff_parse_rules_t const * value_parse_rules_quoted_char[UINT8_MAX]
#define CAST_IP_FIX_COMBO
void fr_value_box_list_untaint(fr_value_box_list_t *head)
Untaint every list member (and their children)
fr_sbuff_parse_rules_t const value_parse_rules_bareword_unquoted
Default formatting rules.
static int fr_value_box_cast_to_ipv4addr(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 any supported type to an IPv4 address.
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.
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.
fr_sbuff_unescape_rules_t fr_value_unescape_solidus
bool fr_value_box_is_truthy(fr_value_box_t const *in)
Check truthiness of values.
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.
fr_sbuff_parse_rules_t const value_parse_rules_single_quoted
static uint8_t const v4_v6_map[]
v4 to v6 mapping prefix
int fr_value_box_mem_append(TALLOC_CTX *ctx, fr_value_box_t *dst, uint8_t const *src, size_t len, bool tainted)
Append data to an existing fr_value_box_t.
fr_sbuff_unescape_rules_t * fr_value_unescape_by_char[UINT8_MAX+1]
void fr_value_box_list_debug(fr_value_box_list_t const *head)
Print a list of value boxes as info messages.
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.
fr_sbuff_escape_rules_t fr_value_escape_solidus
void fr_value_box_copy_shallow(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t const *src)
Perform a shallow copy of a value_box.
static int fr_value_box_cast_to_octets(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 any supported type to octets.
return fr_dbuff_set(dbuff, &our_dbuff)
void fr_value_box_increment(fr_value_box_t *vb)
Increment a boxed value.
fr_sbuff_escape_rules_t * fr_value_escape_by_quote[T_TOKEN_LAST]
ssize_t fr_value_box_list_concat_as_string(bool *tainted, bool *secret, 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, bool flatten)
Concatenate a list of value boxes together.
void _fr_value_box_mark_safe_for(fr_value_box_t *vb, fr_value_box_safe_for_t safe_for)
Mark a value-box as "safe", of a particular type.
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_clear_value(fr_value_box_t *data)
Clear/free any existing value.
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.
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.
#define network_max_size(_x)
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.
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.
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)
static int fr_value_box_cast_to_integer(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 any value to a signed or unsigned integer.
fr_sbuff_escape_rules_t fr_value_escape_unprintables
static int fr_value_box_cast_to_ipv6prefix(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 any supported type to an IPv6 address.
fr_sbuff_escape_rules_t fr_value_escape_backtick
int fr_value_box_bstr_append_buffer(TALLOC_CTX *ctx, fr_value_box_t *dst, char const *src, bool tainted)
Append a talloced buffer to an existing fr_value_box_t.
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.
void fr_value_box_list_taint(fr_value_box_list_t *head)
Taint every list member (and their children)
FR_SBUFF_SET_RETURN(sbuff, &our_sbuff)
static int fr_value_box_cidr_cmp_op(fr_token_t op, int bytes, uint8_t a_net, uint8_t const *a, uint8_t b_net, uint8_t const *b)
static void fr_value_box_copy_meta(fr_value_box_t *dst, fr_value_box_t const *src)
Copy flags and type data from one value box to another.
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.
fr_sbuff_escape_rules_t * fr_value_escape_by_char[UINT8_MAX+1]
static int fr_value_box_fixed_size_from_octets(fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, fr_value_box_t const *src)
Convert octets to a fixed size value box value.
static int fr_value_box_cast_to_bool(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 any supported type to a bool.
fr_sbuff_unescape_rules_t fr_value_unescape_backtick
int fr_value_unbox_ipaddr(fr_ipaddr_t *dst, fr_value_box_t *src)
Unbox an IP address performing a type check.
fr_sbuff_parse_rules_t const value_parse_rules_bareword_quoted
static uint64_t const fr_value_box_integer_max[]
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.
fr_sbuff_parse_rules_t const value_parse_rules_solidus_unquoted
fr_sbuff_parse_rules_t const value_parse_rules_backtick_quoted
fr_sbuff_parse_rules_t const * value_parse_rules_unquoted[T_TOKEN_LAST]
Parse rules for non-quoted strings.
static int fr_value_box_cast_to_ipv4prefix(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 any supported type to an IPv6 address.
static int fr_value_box_cast_to_ethernet(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 any supported type to an ethernet address.
fr_sbuff_unescape_rules_t fr_value_unescape_single
fr_sbuff_parse_rules_t const value_parse_rules_backtick_unquoted
fr_sbuff_parse_rules_t const value_parse_rules_double_quoted
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_sbuff_unescape_rules_t * fr_value_unescape_by_quote[T_TOKEN_LAST]
#define SIGN_PROMOTE(_int, _len)
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.
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.
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.
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.
void fr_value_box_clear(fr_value_box_t *data)
Clear/free any existing value and metadata.
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.
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.
static int64_t const fr_value_box_integer_min[]
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.
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.
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)
int fr_regex_cmp_op(fr_token_t op, fr_value_box_t const *a, fr_value_box_t const *b)
Compare two boxes using an operator.
fr_sbuff_unescape_rules_t fr_value_unescape_double
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.
int fr_value_box_escape_in_place(fr_value_box_t *vb, fr_value_box_escape_t escape, fr_value_box_safe_for_t safe_for, void *uctx)
Escape a single value box in place.
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.
fr_sbuff_escape_rules_t fr_value_escape_secret
Escape secret fields by simply mashing all data to '.
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.
static int fr_value_box_cast_to_ipv6addr(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 any supported type to an IPv6 address.
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.
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.
static int fr_value_box_cast_integer_to_integer(UNUSED 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 any signed or unsigned integer type to any other signed or unsigned integer type.
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_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.
#define vb_should_free(_action)
#define fr_value_box_list_foreach_safe(_list_head, _iter)
#define vb_should_free_value(_action)
#define vb_should_remove(_action)
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.
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_contains_secret(fr_value_box_t const *box)
#define FR_VALUE_BOX_NET_ERROR
Special value to indicate fr_value_box_from_network experienced a general error.
static void fr_value_box_set_secret(fr_value_box_t *box, bool secret)
int(* fr_value_box_escape_t)(fr_value_box_t *vb, void *uctx)
Escape a value box.
#define fr_box_strvalue_len(_val, _len)
#define FR_VALUE_BOX_MAGIC
#define fr_value_box_init_null(_vb)
Initialise an empty/null box that will be filled later.
static size_t char fr_sbuff_t size_t inlen
uintptr_t fr_value_box_safe_for_t
Escaping that's been applied to a value box.
#define fr_value_box_alloc_null(_ctx)
Allocate a value box for later use with a value assignment function.
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)
#define fr_value_box_init(_vb, _type, _enumv, _tainted)
Initialise a fr_value_box_t.
#define fr_value_box_list_foreach(_list_head, _iter)
#define FR_VALUE_BOX_NET_OOM
Special value to indicate fr_value_box_from_network hit an out of memory error.
static size_t char ** out
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.