]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add more data types to "cast to bool"
authorAlan T. DeKok <aland@freeradius.org>
Tue, 16 Nov 2021 00:44:39 +0000 (19:44 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 16 Nov 2021 01:15:38 +0000 (20:15 -0500)
src/lib/util/value.c

index b1ddf7dabf91427cc61472815b3a46c2585b986b..594f1f66ace82e517d46bdcd0c1d25fcdfce4f13 100644 (file)
@@ -54,6 +54,8 @@ RCSID("$Id$")
 #include <freeradius-devel/util/dcursor.h>
 #include <freeradius-devel/util/time.h>
 
+#include <math.h>
+
 /** Sanity checks
  *
  * There should never be an instance where these fail.
@@ -2676,6 +2678,9 @@ static inline int fr_value_box_cast_to_bool(TALLOC_CTX *ctx, fr_value_box_t *dst
                                             NULL, src->tainted);
 
        case FR_TYPE_OCTETS:
+               /*
+                *      This is really "bool from network"
+                */
                return fr_value_box_fixed_size_from_octets(dst, dst_type, dst_enumv, src);
 
        default:
@@ -2720,6 +2725,22 @@ static inline int fr_value_box_cast_to_bool(TALLOC_CTX *ctx, fr_value_box_t *dst
                dst->vb_bool = (src->vb_uint64 != 0);
                break;
 
+       case FR_TYPE_SIZE:
+               dst->vb_bool = (src->vb_size != 0);
+               break;
+
+       case FR_TYPE_TIME_DELTA:
+               dst->vb_bool = (fr_time_delta_unwrap(src->vb_time_delta) != 0);
+               break;
+
+       case FR_TYPE_FLOAT32:
+               dst->vb_bool = (fpclassify(src->vb_float32) == FP_ZERO);
+               break;
+
+       case FR_TYPE_FLOAT64:
+               dst->vb_bool = (fpclassify(src->vb_float64) == FP_ZERO);
+               break;
+
        default:
                fr_strerror_printf("Invalid cast from %s to %s.  Unsupported",
                                   fr_table_str_by_value(fr_value_box_type_table, src->type, "<INVALID>"),