]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
functions to get / set typed data into FR_TYPE_VOID
authorAlan T. DeKok <aland@freeradius.org>
Sun, 11 May 2025 22:02:41 +0000 (18:02 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 11 May 2025 22:03:06 +0000 (18:03 -0400)
src/lib/util/value.c
src/lib/util/value.h

index 46ac7eb5dc4552d5647233abf84805e33ac747d3..8ceb7bc21343e7851db7a65323c289bb01e17b7f 100644 (file)
@@ -4728,6 +4728,22 @@ void fr_value_box_memdup_buffer_shallow(TALLOC_CTX *ctx, fr_value_box_t *dst, fr
        dst->vb_length = talloc_array_length(src);
 }
 
+/*
+ *     Assign a void* value to the data type
+ */
+void _fr_value_box_set_void_type(fr_value_box_t *dst, void *ptr)
+{
+       fr_value_box_init(dst, FR_TYPE_VOID, NULL, false);
+       dst->datum.ptr = ptr;
+}
+
+void *_fr_value_box_get_void_type(fr_value_box_t *dst)
+{
+       fr_assert(dst->type == FR_TYPE_VOID);
+       return dst->datum.ptr;
+}
+
+
 /** Increment a boxed value
  *
  * Implements safe integer overflow.
@@ -5646,6 +5662,7 @@ ssize_t fr_value_box_print(fr_sbuff_t *out, fr_value_box_t const *data, fr_sbuff
        case FR_TYPE_NULL:
                FR_SBUFF_IN_STRCPY_LITERAL_RETURN(&our_out, "NULL");
                break;
+
        /*
         *      Don't add default here
         */
@@ -5654,10 +5671,13 @@ ssize_t fr_value_box_print(fr_sbuff_t *out, fr_value_box_t const *data, fr_sbuff
        case FR_TYPE_VSA:               /* Not a box type */
        case FR_TYPE_VENDOR:            /* Not a box type */
        case FR_TYPE_VALUE_BOX:
-       case FR_TYPE_VOID:
        case FR_TYPE_MAX:
                (void)fr_cond_assert(0);
                return 0;
+
+       case FR_TYPE_VOID:
+               FR_SBUFF_IN_STRCPY_LITERAL_RETURN(&our_out, "..."); /* @todo - cache and then print the data type? */
+               break;
        }
 
 done:
index d1bb8371baa536bba7cda486b448ea735c4ffa2e..ec9de4b1eab87a4750024dd7e65d700cb67e5397 100644 (file)
@@ -1198,6 +1198,14 @@ void             fr_value_box_memdup_buffer_shallow(TALLOC_CTX *ctx, fr_value_box_t *dst, f
 void           fr_value_box_increment(fr_value_box_t *vb)
                CC_HINT(nonnull);
 
+
+
+#define                fr_value_box_set_void_type(_dst, _ptr, _type) _fr_value_box_set_void_type(_dst, talloc_get_type_abort(_ptr, _type))
+void           _fr_value_box_set_void_type(fr_value_box_t *dst, void *ptr);
+
+#define                fr_value_box_get_void_type(_dst, _type) talloc_get_type_abort(_fr_value_box_get_void_type(_dst), _type)
+void           *_fr_value_box_get_void_type(fr_value_box_t *dst);
+
 /** @name Parsing
  *
  * @{