]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
print casts for values of raw attributes
authorAlan T. DeKok <aland@freeradius.org>
Wed, 13 Nov 2024 13:01:00 +0000 (08:01 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 13 Nov 2024 13:01:48 +0000 (08:01 -0500)
now that we parse the cast, they should be printed, too

src/lib/util/pair_print.c
src/tests/unit/protocols/cbor/base.txt

index f01f25ea9125e6379ab68063da21b4ef14f09127..b8b64f7543308f717a1a653ff9df61c9c91b2d98 100644 (file)
 ssize_t fr_pair_print_value_quoted(fr_sbuff_t *out, fr_pair_t const *vp, fr_token_t quote)
 {
        fr_sbuff_t      our_out;
+       ssize_t         slen;
 
        PAIR_VERIFY(vp);
 
+       our_out = FR_SBUFF(out);
+
        switch (vp->vp_type) {
        /*
         *      For structural types descend down
         */
        case FR_TYPE_STRUCTURAL:
-               our_out = FR_SBUFF(out);
                if (fr_pair_list_empty(&vp->vp_group)) {
                        FR_SBUFF_IN_CHAR_RETURN(&our_out, '{', ' ', '}');
 
@@ -66,8 +68,21 @@ ssize_t fr_pair_print_value_quoted(fr_sbuff_t *out, fr_pair_t const *vp, fr_toke
         *      For simple types just print the box
         */
        default:
-               return fr_value_box_print_quoted(out, &vp->data, quote);
+               /*
+                *      If it's raw / unknown and not octets, print the cast before the type.
+                *
+                *      Otherwise on parsing, we don't know how to interpret the value. :(
+                */
+               if ((vp->da->flags.is_raw || vp->da->flags.is_unknown) &&
+                   (vp->vp_type != FR_TYPE_OCTETS)) {
+                       FR_SBUFF_IN_SPRINTF_RETURN(&our_out, "(%s) ", fr_type_to_str(vp->vp_type));
+               }
+
+               slen = fr_value_box_print_quoted(&our_out, &vp->data, quote);
+               if (slen <= 0) return slen;
        }
+
+       FR_SBUFF_SET_RETURN(out, &our_out);
 }
 
 /** Print one attribute and value to a string
index a528f8c21aa0a0dc27142a1be14dfe912832a3ec..e515f6f5bef242bf5451f498698f101bc95df9de 100644 (file)
@@ -64,7 +64,7 @@ match Vendor-Specific = { Nokia-SR = { Dhcp6-Renew-Time = 3600.5 } }
 #  But because CBOR is typed, we can decode typed data.
 #
 decode-pair 9f a1 18 1a 9f a1 19 19 7f 9f a1 18 ff d9 03 ea a2 01 19 0e 10 28 1a 1d cd 65 00 ff ff ff
-match Vendor-Specific = { Nokia-SR = { raw.255 = 3600.5 } }
+match Vendor-Specific = { Nokia-SR = { raw.255 = (time_delta) 3600.5 } }
 
 #
 #  Note that we have to add a cast here :(